mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-11-22 12:16:21 +01:00
Update VV ItemRewriter API Usage (#716)
This commit is contained in:
parent
2b953556ec
commit
39d3265463
@ -67,7 +67,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
|||||||
|
|
||||||
// Save original id, set remapped id
|
// Save original id, set remapped id
|
||||||
final CompoundTag tag = createCustomTag(item);
|
final CompoundTag tag = createCustomTag(item);
|
||||||
tag.putInt(getNbtTagName() + "|id", item.identifier());
|
tag.putInt(nbtTagName("id"), item.identifier());
|
||||||
item.setIdentifier(mappedItem.getId());
|
item.setIdentifier(mappedItem.getId());
|
||||||
|
|
||||||
// Add custom model data
|
// Add custom model data
|
||||||
@ -95,7 +95,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
|||||||
|
|
||||||
final CompoundTag tag = customTag(item);
|
final CompoundTag tag = customTag(item);
|
||||||
if (tag != null) {
|
if (tag != null) {
|
||||||
final Tag originalId = tag.remove(getNbtTagName() + "|id");
|
final Tag originalId = tag.remove(nbtTagName("id"));
|
||||||
if (originalId instanceof IntTag) {
|
if (originalId instanceof IntTag) {
|
||||||
item.setIdentifier(((NumberTag) originalId).asInt());
|
item.setIdentifier(((NumberTag) originalId).asInt());
|
||||||
}
|
}
|
||||||
|
@ -68,10 +68,10 @@ public class EnchantmentRewriter {
|
|||||||
CompoundTag tag = item.tag();
|
CompoundTag tag = item.tag();
|
||||||
if (tag == null) return;
|
if (tag == null) return;
|
||||||
|
|
||||||
if (tag.contains(itemRewriter.getNbtTagName() + "|Enchantments")) {
|
if (tag.contains(itemRewriter.nbtTagName("Enchantments"))) {
|
||||||
rewriteEnchantmentsToServer(tag, false);
|
rewriteEnchantmentsToServer(tag, false);
|
||||||
}
|
}
|
||||||
if (tag.contains(itemRewriter.getNbtTagName() + "|StoredEnchantments")) {
|
if (tag.contains(itemRewriter.nbtTagName("StoredEnchantments"))) {
|
||||||
rewriteEnchantmentsToServer(tag, true);
|
rewriteEnchantmentsToServer(tag, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save original id, set remapped id
|
// Save original id, set remapped id
|
||||||
item.tag().putInt(getNbtTagName() + "|id", item.identifier());
|
item.tag().putInt(nbtTagName("id"), item.identifier());
|
||||||
item.setIdentifier(data.getId());
|
item.setIdentifier(data.getId());
|
||||||
|
|
||||||
// Add custom model data
|
// Add custom model data
|
||||||
@ -105,7 +105,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
}
|
}
|
||||||
if (!display.contains("Name")) {
|
if (!display.contains("Name")) {
|
||||||
display.put("Name", new StringTag(data.getJsonName()));
|
display.put("Name", new StringTag(data.getJsonName()));
|
||||||
display.put(getNbtTagName() + "|customName", new ByteTag());
|
display.put(nbtTagName("customName"), new ByteTag());
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
@ -116,7 +116,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
|
|
||||||
super.handleItemToServer(item);
|
super.handleItemToServer(item);
|
||||||
if (item.tag() != null) {
|
if (item.tag() != null) {
|
||||||
Tag originalId = item.tag().remove(getNbtTagName() + "|id");
|
Tag originalId = item.tag().remove(nbtTagName("id"));
|
||||||
if (originalId instanceof IntTag) {
|
if (originalId instanceof IntTag) {
|
||||||
item.setIdentifier(((NumberTag) originalId).asInt());
|
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> {
|
T extends BackwardsProtocol<C, ?, ?, S>> extends ItemRewriter<C, S, T> {
|
||||||
|
|
||||||
protected final boolean jsonNameFormat;
|
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) {
|
protected ItemRewriterBase(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType, Type<Item> mappedItemType, Type<Item[]> mappedItemArrayType, boolean jsonFormat) {
|
||||||
super(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType);
|
super(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType);
|
||||||
this.jsonNameFormat = jsonFormat;
|
this.jsonNameFormat = jsonFormat;
|
||||||
protocolName = protocol.getClass().getSimpleName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ItemRewriterBase(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType, boolean jsonNameFormat) {
|
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) {
|
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) {
|
protected void saveStringTag(CompoundTag displayTag, StringTag original, String name) {
|
||||||
// Multiple places might try to backup data
|
// Multiple places might try to backup data
|
||||||
String backupName = getNbtTagName() + "|o" + name;
|
String backupName = nbtTagName("o" + name);
|
||||||
if (!displayTag.contains(backupName)) {
|
if (!displayTag.contains(backupName)) {
|
||||||
displayTag.putString(backupName, original.getValue());
|
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) {
|
protected void saveListTag(CompoundTag displayTag, ListTag<?> original, String name) {
|
||||||
// Multiple places might try to backup data
|
// Multiple places might try to backup data
|
||||||
String backupName = getNbtTagName() + "|o" + name;
|
String backupName = nbtTagName("o" + name);
|
||||||
if (!displayTag.contains(backupName)) {
|
if (!displayTag.contains(backupName)) {
|
||||||
displayTag.put(backupName, original.copy());
|
displayTag.put(backupName, original.copy());
|
||||||
}
|
}
|
||||||
@ -80,7 +78,7 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
|
|||||||
CompoundTag display = item.tag().getCompoundTag("display");
|
CompoundTag display = item.tag().getCompoundTag("display");
|
||||||
if (display != null) {
|
if (display != null) {
|
||||||
// Remove custom name / restore original name
|
// Remove custom name / restore original name
|
||||||
if (display.remove(getNbtTagName() + "|customName") != null) {
|
if (display.remove(nbtTagName("customName")) != null) {
|
||||||
display.remove("Name");
|
display.remove("Name");
|
||||||
} else {
|
} else {
|
||||||
restoreStringTag(display, "Name");
|
restoreStringTag(display, "Name");
|
||||||
@ -92,20 +90,16 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void restoreStringTag(CompoundTag tag, String tagName) {
|
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) {
|
if (original instanceof StringTag) {
|
||||||
tag.putString(tagName, ((StringTag) original).getValue());
|
tag.putString(tagName, ((StringTag) original).getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void restoreListTag(CompoundTag tag, String tagName) {
|
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) {
|
if (original instanceof ListTag) {
|
||||||
tag.put(tagName, ((ListTag<?>) original).copy());
|
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();
|
short originalData = item.data();
|
||||||
item.tag().putInt(getNbtTagName() + "|id", item.identifier());
|
item.tag().putInt(nbtTagName("id"), item.identifier());
|
||||||
item.setIdentifier(data.getId());
|
item.setIdentifier(data.getId());
|
||||||
// Keep original data if mapped data is set to -1
|
// Keep original data if mapped data is set to -1
|
||||||
if (data.getData() != -1) {
|
if (data.getData() != -1) {
|
||||||
item.setData(data.getData());
|
item.setData(data.getData());
|
||||||
item.tag().putShort(getNbtTagName() + "|data", originalData);
|
item.tag().putShort(nbtTagName("data"), originalData);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set display name
|
// Set display name
|
||||||
@ -173,7 +173,7 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
|||||||
if (nameTag == null) {
|
if (nameTag == null) {
|
||||||
nameTag = new StringTag(data.getName());
|
nameTag = new StringTag(data.getName());
|
||||||
display.put("Name", nameTag);
|
display.put("Name", nameTag);
|
||||||
display.put(getNbtTagName() + "|customName", new ByteTag());
|
display.put(nbtTagName("customName"), new ByteTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle colors
|
// Handle colors
|
||||||
@ -190,11 +190,11 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
|||||||
if (item == null) return null;
|
if (item == null) return null;
|
||||||
super.handleItemToServer(item);
|
super.handleItemToServer(item);
|
||||||
if (item.tag() != null) {
|
if (item.tag() != null) {
|
||||||
Tag originalId = item.tag().remove(getNbtTagName() + "|id");
|
Tag originalId = item.tag().remove(nbtTagName("id"));
|
||||||
if (originalId instanceof IntTag) {
|
if (originalId instanceof IntTag) {
|
||||||
item.setIdentifier(((NumberTag) originalId).asInt());
|
item.setIdentifier(((NumberTag) originalId).asInt());
|
||||||
}
|
}
|
||||||
Tag originalData = item.tag().remove(getNbtTagName() + "|data");
|
Tag originalData = item.tag().remove(nbtTagName("data"));
|
||||||
if (originalData instanceof ShortTag) {
|
if (originalData instanceof ShortTag) {
|
||||||
item.setData(((NumberTag) originalData).asShort());
|
item.setData(((NumberTag) originalData).asShort());
|
||||||
}
|
}
|
||||||
|
@ -280,7 +280,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
|
|||||||
return tag;
|
return tag;
|
||||||
});
|
});
|
||||||
|
|
||||||
enchantmentRewriter = new LegacyEnchantmentRewriter(getNbtTagName());
|
enchantmentRewriter = new LegacyEnchantmentRewriter(nbtTagName());
|
||||||
enchantmentRewriter.registerEnchantment(71, "§cCurse of Vanishing");
|
enchantmentRewriter.registerEnchantment(71, "§cCurse of Vanishing");
|
||||||
enchantmentRewriter.registerEnchantment(10, "§cCurse of Binding");
|
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.minecraft.item.Item;
|
||||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
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.ClientboundPackets1_9_3;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_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
|
@Override
|
||||||
protected void registerRewrites() {
|
protected void registerRewrites() {
|
||||||
enchantmentRewriter = new LegacyEnchantmentRewriter(getNbtTagName());
|
enchantmentRewriter = new LegacyEnchantmentRewriter(nbtTagName());
|
||||||
enchantmentRewriter.registerEnchantment(22, "§7Sweeping Edge");
|
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) {
|
public BlockItemPackets1_13(Protocol1_12_2To1_13 protocol) {
|
||||||
super(protocol, null, null);
|
super(protocol, null, null);
|
||||||
extraNbtTag = getNbtTagName() + "|2";
|
extraNbtTag = nbtTagName("2");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isDamageable(int id) {
|
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());
|
final String pattern = Key.stripMinecraftNamespace(patternTag.getValue());
|
||||||
if (NEW_TRIM_PATTERNS.contains(pattern)) {
|
if (NEW_TRIM_PATTERNS.contains(pattern)) {
|
||||||
tag.remove("Trim");
|
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
|
// Add back original trim tag
|
||||||
final Tag trimTag;
|
final Tag trimTag;
|
||||||
final CompoundTag tag = item.tag();
|
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);
|
tag.put("Trim", trimTag);
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
|
Loading…
Reference in New Issue
Block a user