3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-11-20 06:50:10 +01:00

Add item handler methods to LegacyEnchantmentRewriter (#709)

Dieser Commit ist enthalten in:
EnZaXD 2024-03-28 11:22:34 +01:00 committet von GitHub
Ursprung 4547d5c702
Commit 0aacfe3bcb
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
3 geänderte Dateien mit 29 neuen und 30 gelöschten Zeilen

Datei anzeigen

@ -17,6 +17,7 @@
*/ */
package com.viaversion.viabackwards.api.rewriters; package com.viaversion.viabackwards.api.rewriters;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
@ -45,6 +46,30 @@ public class LegacyEnchantmentRewriter {
enchantmentMappings.put((short) id, replacementLore); enchantmentMappings.put((short) id, replacementLore);
} }
public void handleToClient(Item item) {
CompoundTag tag = item.tag();
if (tag == null) return;
if (tag.getListTag("ench") != null) {
rewriteEnchantmentsToClient(tag, false);
}
if (tag.getListTag("StoredEnchantments") != null) {
rewriteEnchantmentsToClient(tag, true);
}
}
public void handleToServer(Item item) {
CompoundTag tag = item.tag();
if (tag == null) return;
if (tag.contains(nbtTagName + "|ench")) {
rewriteEnchantmentsToServer(tag, false);
}
if (tag.contains(nbtTagName + "|StoredEnchantments")) {
rewriteEnchantmentsToServer(tag, true);
}
}
public void rewriteEnchantmentsToClient(CompoundTag tag, boolean storedEnchant) { public void rewriteEnchantmentsToClient(CompoundTag tag, boolean storedEnchant) {
String key = storedEnchant ? "StoredEnchantments" : "ench"; String key = storedEnchant ? "StoredEnchantments" : "ench";
ListTag<CompoundTag> enchantments = tag.getListTag(key, CompoundTag.class); ListTag<CompoundTag> enchantments = tag.getListTag(key, CompoundTag.class);

Datei anzeigen

@ -298,12 +298,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
// Rewrite spawn eggs (id checks are done in the method itself) // Rewrite spawn eggs (id checks are done in the method itself)
EntityIdRewriter.toClientItem(item, true); EntityIdRewriter.toClientItem(item, true);
if (tag.getListTag("ench") != null) { enchantmentRewriter.handleToClient(item);
enchantmentRewriter.rewriteEnchantmentsToClient(tag, false);
}
if (tag.getListTag("StoredEnchantments") != null) {
enchantmentRewriter.rewriteEnchantmentsToClient(tag, true);
}
return item; return item;
} }
@ -318,12 +313,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
// Rewrite spawn eggs (id checks are done in the method itself) // Rewrite spawn eggs (id checks are done in the method itself)
EntityIdRewriter.toServerItem(item, true); EntityIdRewriter.toServerItem(item, true);
if (tag.getListTag(getNbtTagName() + "|ench") != null) { enchantmentRewriter.handleToServer(item);
enchantmentRewriter.rewriteEnchantmentsToServer(tag, false);
}
if (tag.getListTag(getNbtTagName() + "|StoredEnchantments") != null) {
enchantmentRewriter.rewriteEnchantmentsToServer(tag, true);
}
return item; return item;
} }

Datei anzeigen

@ -93,15 +93,7 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<ClientboundPacket
if (item == null) return null; if (item == null) return null;
super.handleItemToClient(item); super.handleItemToClient(item);
CompoundTag tag = item.tag(); enchantmentRewriter.handleToClient(item);
if (tag == null) return item;
if (tag.getListTag("ench") != null) {
enchantmentRewriter.rewriteEnchantmentsToClient(tag, false);
}
if (tag.getListTag("StoredEnchantments") != null) {
enchantmentRewriter.rewriteEnchantmentsToClient(tag, true);
}
return item; return item;
} }
@ -110,15 +102,7 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<ClientboundPacket
if (item == null) return null; if (item == null) return null;
super.handleItemToServer(item); super.handleItemToServer(item);
CompoundTag tag = item.tag(); enchantmentRewriter.handleToServer(item);
if (tag == null) return item;
if (tag.getListTag(getNbtTagName() + "|ench") != null) {
enchantmentRewriter.rewriteEnchantmentsToServer(tag, false);
}
if (tag.getListTag(getNbtTagName() + "|StoredEnchantments") != null) {
enchantmentRewriter.rewriteEnchantmentsToServer(tag, true);
}
return item; return item;
} }
} }