Skip to content

Commit

Permalink
Show version in Item replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Oct 10, 2023
1 parent 14a314d commit 3650a08
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)");
}
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ public abstract class ReplacementItemRewriter<T extends AbstractProtocol<?, ?, ?
private final Int2ObjectMap<Replacement> 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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,7 +34,7 @@ public class ReplacementItemRewriter1_7_6_10 extends ReplacementItemRewriter<Pro
private final static String VIA_REWIND_TAG_KEY = "ViaRewind1_7_6_10to1_8";

public ReplacementItemRewriter1_7_6_10(Protocol1_7_6_10To1_8 protocol) {
super(protocol);
super(protocol, ProtocolVersion.v1_8.getName());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.viaversion.viarewind.api.rewriter.ReplacementItemRewriter;
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 com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter;

Expand All @@ -35,7 +36,7 @@ public class ReplacementItemRewriter1_8 extends ReplacementItemRewriter<Protocol
public final static String VIA_REWIND_TAG_KEY = "ViaRewind1_8to1_9";

public ReplacementItemRewriter1_8(Protocol1_8To1_9 protocol) {
super(protocol);
super(protocol, ProtocolVersion.v1_9.getName());
}

@Override
Expand Down

0 comments on commit 3650a08

Please sign in to comment.