From 3650a0875284c6f5a402fb69d95cc46d8d0c7a82 Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Wed, 11 Oct 2023 01:08:35 +0200 Subject: [PATCH] Show version in Item replacements --- .../viarewind/api/rewriter/Replacement.java | 11 +++++++---- .../api/rewriter/ReplacementItemRewriter.java | 6 +++++- .../rewriter/ReplacementItemRewriter1_7_6_10.java | 3 ++- .../rewriter/ReplacementItemRewriter1_8.java | 3 ++- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/com/viaversion/viarewind/api/rewriter/Replacement.java b/common/src/main/java/com/viaversion/viarewind/api/rewriter/Replacement.java index 912649354..d80b87760 100644 --- a/common/src/main/java/com/viaversion/viarewind/api/rewriter/Replacement.java +++ b/common/src/main/java/com/viaversion/viarewind/api/rewriter/Replacement.java @@ -21,6 +21,7 @@ import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; +import com.viaversion.viaversion.util.ChatColorUtil; public class Replacement { private final int id; @@ -46,10 +47,12 @@ public Replacement(final int id, final int data, final String name) { this.id = id; this.data = data; this.name = name; + } - if (name != null) { - this.resetName = "§r" + name; - this.bracketName = " §r§7(" + name + "§r§7)"; + public void buildNames(final String protocolVersion) { + if (this.name != null) { + this.resetName = ChatColorUtil.translateAlternateColorCodes("&r" + protocolVersion + " " + this.name); + this.bracketName = ChatColorUtil.translateAlternateColorCodes(" &r&7(" + protocolVersion + " " + this.name + "&r&7)"); } } @@ -69,7 +72,7 @@ public String getName() { * @param item The item to replace * @return The replacement for the item or the item if not found */ - public Item replace(Item item) { + public Item replace(final Item item) { item.setIdentifier(id); // Set the new id if (data != -1) { item.setData((short) data); // Set the new data diff --git a/common/src/main/java/com/viaversion/viarewind/api/rewriter/ReplacementItemRewriter.java b/common/src/main/java/com/viaversion/viarewind/api/rewriter/ReplacementItemRewriter.java index 2551e547b..470ab8037 100644 --- a/common/src/main/java/com/viaversion/viarewind/api/rewriter/ReplacementItemRewriter.java +++ b/common/src/main/java/com/viaversion/viarewind/api/rewriter/ReplacementItemRewriter.java @@ -30,9 +30,11 @@ public abstract class ReplacementItemRewriter BLOCK_REPLACEMENTS = new Int2ObjectOpenHashMap<>(); private final T protocol; + private final String protocolName; - public ReplacementItemRewriter(T protocol) { + public ReplacementItemRewriter(final T protocol, final String protocolName) { this.protocol = protocol; + this.protocolName = protocolName; } public void registerItem(int id, Replacement replacement) { @@ -49,10 +51,12 @@ public void registerItemBlock(int id, Replacement replacement) { public void registerItem(int id, int data, Replacement replacement) { ITEM_REPLACEMENTS.put(generateTrackingId(id, data), replacement); + replacement.buildNames(protocolName); } public void registerBlock(int id, int data, Replacement replacement) { BLOCK_REPLACEMENTS.put(generateTrackingId(id, data), replacement); + replacement.buildNames(protocolName); } public void registerItemBlock(int id, int data, Replacement replacement) { diff --git a/common/src/main/java/com/viaversion/viarewind/protocol/protocol1_7_6_10to1_8/rewriter/ReplacementItemRewriter1_7_6_10.java b/common/src/main/java/com/viaversion/viarewind/protocol/protocol1_7_6_10to1_8/rewriter/ReplacementItemRewriter1_7_6_10.java index e1ead49c2..38676a12b 100644 --- a/common/src/main/java/com/viaversion/viarewind/protocol/protocol1_7_6_10to1_8/rewriter/ReplacementItemRewriter1_7_6_10.java +++ b/common/src/main/java/com/viaversion/viarewind/protocol/protocol1_7_6_10to1_8/rewriter/ReplacementItemRewriter1_7_6_10.java @@ -24,6 +24,7 @@ import com.viaversion.viarewind.utils.ChatUtil; import com.viaversion.viarewind.utils.Enchantments; import com.viaversion.viaversion.api.minecraft.item.Item; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.libs.opennbt.tag.builtin.*; import java.util.ArrayList; @@ -33,7 +34,7 @@ public class ReplacementItemRewriter1_7_6_10 extends ReplacementItemRewriter