Skip to content

Commit 2cb45b7

Browse files
authored
Merge pull request #466 from UnicacityAddon/feature/faction-colored-hitboxes
feature/faction-colored-hitboxes
2 parents 4b768ee + 420afcc commit 2cb45b7

4 files changed

Lines changed: 47 additions & 21 deletions

File tree

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ loom {
9696
runs {
9797
named("client") {
9898
property("devauth.enabled", "1")
99+
property("mixin.debug.export", "true")
99100
}
100101
}
101102
}

src/main/java/de/rettichlp/ucutils/common/models/Faction.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,27 @@
33
import lombok.AllArgsConstructor;
44
import lombok.Getter;
55
import net.minecraft.ChatFormatting;
6-
import net.minecraft.network.chat.Component;
7-
import org.jetbrains.annotations.NotNull;
86

9-
import java.util.Optional;
7+
import java.awt.Color;
108

11-
import static java.util.Arrays.stream;
129
import static net.minecraft.ChatFormatting.BLUE;
1310
import static net.minecraft.ChatFormatting.DARK_AQUA;
1411
import static net.minecraft.ChatFormatting.DARK_BLUE;
15-
import static net.minecraft.ChatFormatting.DARK_GRAY;
1612
import static net.minecraft.ChatFormatting.DARK_PURPLE;
1713
import static net.minecraft.ChatFormatting.DARK_RED;
1814
import static net.minecraft.ChatFormatting.GOLD;
1915
import static net.minecraft.ChatFormatting.GRAY;
2016
import static net.minecraft.ChatFormatting.GREEN;
2117
import static net.minecraft.ChatFormatting.LIGHT_PURPLE;
2218
import static net.minecraft.ChatFormatting.RED;
19+
import static net.minecraft.ChatFormatting.WHITE;
2320
import static net.minecraft.ChatFormatting.YELLOW;
24-
import static net.minecraft.network.chat.Component.empty;
25-
import static net.minecraft.network.chat.Component.literal;
2621

2722
@Getter
2823
@AllArgsConstructor
2924
public enum Faction {
3025

31-
NULL("", "", false, GRAY, ""),
26+
NULL("", "", false, WHITE, ""),
3227
FBI("FBI", "fbi", false, DARK_BLUE, "✯"),
3328
POLIZEI("Polizei", "police", false, BLUE, "✯"),
3429
RETTUNGSDIENST("Rettungsdienst", "medic", false, DARK_RED, "✚"),
@@ -49,18 +44,7 @@ public enum Faction {
4944
private final ChatFormatting color;
5045
private final String icon;
5146

52-
public Component getNameTagSuffix() {
53-
return this != NULL
54-
? empty()
55-
.append(literal("⌜").withStyle(DARK_GRAY))
56-
.append(literal(this.icon).withStyle(this.color))
57-
.append(literal("⌟").withStyle(DARK_GRAY))
58-
: empty();
59-
}
60-
61-
public static @NotNull Optional<Faction> fromDisplayName(String displayName) {
62-
return stream(values())
63-
.filter(faction -> faction.getDisplayName().equals(displayName))
64-
.findFirst();
47+
public Color getAwtColor() {
48+
return this.color.getColor() != null ? new Color(this.color.getColor()) : Color.WHITE;
6549
}
6650
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package de.rettichlp.ucutils.mixin;
2+
3+
import com.llamalad7.mixinextras.sugar.Local;
4+
import de.rettichlp.ucutils.common.models.Faction;
5+
import net.minecraft.client.renderer.debug.EntityHitboxDebugRenderer;
6+
import net.minecraft.gizmos.GizmoStyle;
7+
import net.minecraft.world.entity.Entity;
8+
import net.minecraft.world.entity.player.Player;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.injection.At;
11+
import org.spongepowered.asm.mixin.injection.ModifyArg;
12+
13+
import static de.rettichlp.ucutils.UCUtils.storage;
14+
import static java.util.Optional.ofNullable;
15+
import static net.minecraft.gizmos.GizmoStyle.stroke;
16+
17+
@Mixin(EntityHitboxDebugRenderer.class)
18+
public abstract class EntityHitboxDebugRendererMixin {
19+
20+
@ModifyArg(method = "showHitboxes",
21+
at = @At(value = "INVOKE",
22+
target = "Lnet/minecraft/gizmos/Gizmos;cuboid(Lnet/minecraft/world/phys/AABB;Lnet/minecraft/gizmos/GizmoStyle;)Lnet/minecraft/gizmos/GizmoProperties;",
23+
ordinal = 0),
24+
index = 1)
25+
private GizmoStyle ucutils$showHitboxesInvoke(GizmoStyle style,
26+
@Local(name = "entity", argsOnly = true) Entity entity,
27+
@Local(name = "isServerEntity", argsOnly = true) boolean isServerEntity) {
28+
if (!storage.isUnicaCity()) {
29+
return style;
30+
}
31+
32+
if (!(entity instanceof Player player) || isServerEntity) {
33+
return style;
34+
}
35+
36+
String playerName = player.getPlainTextName();
37+
Faction faction = ofNullable(storage.getPlayerFactionCache().get(playerName)).orElseGet(() -> storage.getFaction(playerName));
38+
return stroke(faction.getAwtColor().getRGB());
39+
}
40+
}

src/main/resources/ucutils.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"ChatScreenMixin",
2020
"ClientPacketListenerMixin",
2121
"ClientPlayNetworkHandlerMixin",
22+
"EntityHitboxDebugRendererMixin",
2223
"EntityRendererMixin",
2324
"GuiMixin",
2425
"LivingEntityMixin",

0 commit comments

Comments
 (0)