Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-11-17 13:30:14 +01:00
Update VV ItemRewriter API Usage (#716)
Dieser Commit ist enthalten in:
Ursprung
2b953556ec
Commit
39d3265463
@ -67,7 +67,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
|
||||
// Save original id, set remapped id
|
||||
final CompoundTag tag = createCustomTag(item);
|
||||
tag.putInt(getNbtTagName() + "|id", item.identifier());
|
||||
tag.putInt(nbtTagName("id"), item.identifier());
|
||||
item.setIdentifier(mappedItem.getId());
|
||||
|
||||
// Add custom model data
|
||||
@ -95,7 +95,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
|
||||
final CompoundTag tag = customTag(item);
|
||||
if (tag != null) {
|
||||
final Tag originalId = tag.remove(getNbtTagName() + "|id");
|
||||
final Tag originalId = tag.remove(nbtTagName("id"));
|
||||
if (originalId instanceof IntTag) {
|
||||
item.setIdentifier(((NumberTag) originalId).asInt());
|
||||
}
|
||||
|
@ -68,10 +68,10 @@ public class EnchantmentRewriter {
|
||||
CompoundTag tag = item.tag();
|
||||
if (tag == null) return;
|
||||
|
||||
if (tag.contains(itemRewriter.getNbtTagName() + "|Enchantments")) {
|
||||
if (tag.contains(itemRewriter.nbtTagName("Enchantments"))) {
|
||||
rewriteEnchantmentsToServer(tag, false);
|
||||
}
|
||||
if (tag.contains(itemRewriter.getNbtTagName() + "|StoredEnchantments")) {
|
||||
if (tag.contains(itemRewriter.nbtTagName("StoredEnchantments"))) {
|
||||
rewriteEnchantmentsToServer(tag, true);
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
||||
}
|
||||
|
||||
// Save original id, set remapped id
|
||||
item.tag().putInt(getNbtTagName() + "|id", item.identifier());
|
||||
item.tag().putInt(nbtTagName("id"), item.identifier());
|
||||
item.setIdentifier(data.getId());
|
||||
|
||||
// Add custom model data
|
||||
@ -105,7 +105,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
||||
}
|
||||
if (!display.contains("Name")) {
|
||||
display.put("Name", new StringTag(data.getJsonName()));
|
||||
display.put(getNbtTagName() + "|customName", new ByteTag());
|
||||
display.put(nbtTagName("customName"), new ByteTag());
|
||||
}
|
||||
return item;
|
||||
}
|
||||
@ -116,7 +116,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
||||
|
||||
super.handleItemToServer(item);
|
||||
if (item.tag() != null) {
|
||||
Tag originalId = item.tag().remove(getNbtTagName() + "|id");
|
||||
Tag originalId = item.tag().remove(nbtTagName("id"));
|
||||
if (originalId instanceof IntTag) {
|
||||
item.setIdentifier(((NumberTag) originalId).asInt());
|
||||
}
|
||||
|
@ -33,12 +33,10 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
|
||||
T extends BackwardsProtocol<C, ?, ?, S>> extends ItemRewriter<C, S, T> {
|
||||
|
||||
protected final boolean jsonNameFormat;
|
||||
protected final String protocolName;
|
||||
|
||||
protected ItemRewriterBase(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType, Type<Item> mappedItemType, Type<Item[]> mappedItemArrayType, boolean jsonFormat) {
|
||||
super(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType);
|
||||
this.jsonNameFormat = jsonFormat;
|
||||
protocolName = protocol.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
protected ItemRewriterBase(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType, boolean jsonNameFormat) {
|
||||
@ -55,12 +53,12 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
|
||||
}
|
||||
|
||||
protected boolean hasBackupTag(CompoundTag displayTag, String tagName) {
|
||||
return displayTag.contains(getNbtTagName() + "|o" + tagName);
|
||||
return displayTag.contains(nbtTagName("o" + tagName));
|
||||
}
|
||||
|
||||
protected void saveStringTag(CompoundTag displayTag, StringTag original, String name) {
|
||||
// Multiple places might try to backup data
|
||||
String backupName = getNbtTagName() + "|o" + name;
|
||||
String backupName = nbtTagName("o" + name);
|
||||
if (!displayTag.contains(backupName)) {
|
||||
displayTag.putString(backupName, original.getValue());
|
||||
}
|
||||
@ -68,7 +66,7 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
|
||||
|
||||
protected void saveListTag(CompoundTag displayTag, ListTag<?> original, String name) {
|
||||
// Multiple places might try to backup data
|
||||
String backupName = getNbtTagName() + "|o" + name;
|
||||
String backupName = nbtTagName("o" + name);
|
||||
if (!displayTag.contains(backupName)) {
|
||||
displayTag.put(backupName, original.copy());
|
||||
}
|
||||
@ -80,7 +78,7 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
|
||||
CompoundTag display = item.tag().getCompoundTag("display");
|
||||
if (display != null) {
|
||||
// Remove custom name / restore original name
|
||||
if (display.remove(getNbtTagName() + "|customName") != null) {
|
||||
if (display.remove(nbtTagName("customName")) != null) {
|
||||
display.remove("Name");
|
||||
} else {
|
||||
restoreStringTag(display, "Name");
|
||||
@ -92,20 +90,16 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
|
||||
}
|
||||
|
||||
protected void restoreStringTag(CompoundTag tag, String tagName) {
|
||||
Tag original = tag.remove(getNbtTagName() + "|o" + tagName);
|
||||
Tag original = tag.remove(nbtTagName("o" + tagName));
|
||||
if (original instanceof StringTag) {
|
||||
tag.putString(tagName, ((StringTag) original).getValue());
|
||||
}
|
||||
}
|
||||
|
||||
protected void restoreListTag(CompoundTag tag, String tagName) {
|
||||
Tag original = tag.remove(getNbtTagName() + "|o" + tagName);
|
||||
Tag original = tag.remove(nbtTagName("o" + tagName));
|
||||
if (original instanceof ListTag) {
|
||||
tag.put(tagName, ((ListTag<?>) original).copy());
|
||||
}
|
||||
}
|
||||
|
||||
public String getNbtTagName() {
|
||||
return "VB|" + protocolName;
|
||||
}
|
||||
}
|
||||
|
@ -154,12 +154,12 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
}
|
||||
|
||||
short originalData = item.data();
|
||||
item.tag().putInt(getNbtTagName() + "|id", item.identifier());
|
||||
item.tag().putInt(nbtTagName("id"), item.identifier());
|
||||
item.setIdentifier(data.getId());
|
||||
// Keep original data if mapped data is set to -1
|
||||
if (data.getData() != -1) {
|
||||
item.setData(data.getData());
|
||||
item.tag().putShort(getNbtTagName() + "|data", originalData);
|
||||
item.tag().putShort(nbtTagName("data"), originalData);
|
||||
}
|
||||
|
||||
// Set display name
|
||||
@ -173,7 +173,7 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
if (nameTag == null) {
|
||||
nameTag = new StringTag(data.getName());
|
||||
display.put("Name", nameTag);
|
||||
display.put(getNbtTagName() + "|customName", new ByteTag());
|
||||
display.put(nbtTagName("customName"), new ByteTag());
|
||||
}
|
||||
|
||||
// Handle colors
|
||||
@ -190,11 +190,11 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
if (item == null) return null;
|
||||
super.handleItemToServer(item);
|
||||
if (item.tag() != null) {
|
||||
Tag originalId = item.tag().remove(getNbtTagName() + "|id");
|
||||
Tag originalId = item.tag().remove(nbtTagName("id"));
|
||||
if (originalId instanceof IntTag) {
|
||||
item.setIdentifier(((NumberTag) originalId).asInt());
|
||||
}
|
||||
Tag originalData = item.tag().remove(getNbtTagName() + "|data");
|
||||
Tag originalData = item.tag().remove(nbtTagName("data"));
|
||||
if (originalData instanceof ShortTag) {
|
||||
item.setData(((NumberTag) originalData).asShort());
|
||||
}
|
||||
|
@ -280,7 +280,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
|
||||
return tag;
|
||||
});
|
||||
|
||||
enchantmentRewriter = new LegacyEnchantmentRewriter(getNbtTagName());
|
||||
enchantmentRewriter = new LegacyEnchantmentRewriter(nbtTagName());
|
||||
enchantmentRewriter.registerEnchantment(71, "§cCurse of Vanishing");
|
||||
enchantmentRewriter.registerEnchantment(10, "§cCurse of Binding");
|
||||
|
||||
|
@ -24,7 +24,6 @@ import com.viaversion.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
|
||||
|
||||
@ -84,7 +83,7 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<ClientboundPacket
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
enchantmentRewriter = new LegacyEnchantmentRewriter(getNbtTagName());
|
||||
enchantmentRewriter = new LegacyEnchantmentRewriter(nbtTagName());
|
||||
enchantmentRewriter.registerEnchantment(22, "§7Sweeping Edge");
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
|
||||
public BlockItemPackets1_13(Protocol1_12_2To1_13 protocol) {
|
||||
super(protocol, null, null);
|
||||
extraNbtTag = getNbtTagName() + "|2";
|
||||
extraNbtTag = nbtTagName("2");
|
||||
}
|
||||
|
||||
public static boolean isDamageable(int id) {
|
||||
|
@ -166,7 +166,7 @@ public final class BlockItemPackets1_20 extends ItemRewriter<ClientboundPackets1
|
||||
final String pattern = Key.stripMinecraftNamespace(patternTag.getValue());
|
||||
if (NEW_TRIM_PATTERNS.contains(pattern)) {
|
||||
tag.remove("Trim");
|
||||
tag.put(getNbtTagName() + "|Trim", trimTag);
|
||||
tag.put(nbtTagName("Trim"), trimTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -184,7 +184,7 @@ public final class BlockItemPackets1_20 extends ItemRewriter<ClientboundPackets1
|
||||
// Add back original trim tag
|
||||
final Tag trimTag;
|
||||
final CompoundTag tag = item.tag();
|
||||
if (tag != null && (trimTag = tag.remove(getNbtTagName() + "|Trim")) != null) {
|
||||
if (tag != null && (trimTag = tag.remove(nbtTagName("Trim"))) != null) {
|
||||
tag.put("Trim", trimTag);
|
||||
}
|
||||
return item;
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren