Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-12-26 00:00:33 +01:00
Add item handler methods to LegacyEnchantmentRewriter (#709)
Dieser Commit ist enthalten in:
Ursprung
4547d5c702
Commit
0aacfe3bcb
@ -17,6 +17,7 @@
|
||||
*/
|
||||
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.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
|
||||
@ -45,6 +46,30 @@ public class LegacyEnchantmentRewriter {
|
||||
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) {
|
||||
String key = storedEnchant ? "StoredEnchantments" : "ench";
|
||||
ListTag<CompoundTag> enchantments = tag.getListTag(key, CompoundTag.class);
|
||||
|
@ -298,12 +298,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
|
||||
// Rewrite spawn eggs (id checks are done in the method itself)
|
||||
EntityIdRewriter.toClientItem(item, true);
|
||||
|
||||
if (tag.getListTag("ench") != null) {
|
||||
enchantmentRewriter.rewriteEnchantmentsToClient(tag, false);
|
||||
}
|
||||
if (tag.getListTag("StoredEnchantments") != null) {
|
||||
enchantmentRewriter.rewriteEnchantmentsToClient(tag, true);
|
||||
}
|
||||
enchantmentRewriter.handleToClient(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)
|
||||
EntityIdRewriter.toServerItem(item, true);
|
||||
|
||||
if (tag.getListTag(getNbtTagName() + "|ench") != null) {
|
||||
enchantmentRewriter.rewriteEnchantmentsToServer(tag, false);
|
||||
}
|
||||
if (tag.getListTag(getNbtTagName() + "|StoredEnchantments") != null) {
|
||||
enchantmentRewriter.rewriteEnchantmentsToServer(tag, true);
|
||||
}
|
||||
enchantmentRewriter.handleToServer(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
|
@ -93,15 +93,7 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<ClientboundPacket
|
||||
if (item == null) return null;
|
||||
super.handleItemToClient(item);
|
||||
|
||||
CompoundTag tag = item.tag();
|
||||
if (tag == null) return item;
|
||||
|
||||
if (tag.getListTag("ench") != null) {
|
||||
enchantmentRewriter.rewriteEnchantmentsToClient(tag, false);
|
||||
}
|
||||
if (tag.getListTag("StoredEnchantments") != null) {
|
||||
enchantmentRewriter.rewriteEnchantmentsToClient(tag, true);
|
||||
}
|
||||
enchantmentRewriter.handleToClient(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
@ -110,15 +102,7 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<ClientboundPacket
|
||||
if (item == null) return null;
|
||||
super.handleItemToServer(item);
|
||||
|
||||
CompoundTag tag = item.tag();
|
||||
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);
|
||||
}
|
||||
enchantmentRewriter.handleToServer(item);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren