Fix enchantment glint behaviour in 1.10->1.11 (#4156)

This commit is contained in:
EnZaXD 2024-09-23 19:24:46 +02:00 committed by GitHub
parent a0a2794291
commit 5287d4fb4f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -19,6 +19,7 @@ package com.viaversion.viaversion.protocols.v1_10to1_11.rewriter;
import com.viaversion.nbt.tag.ByteTag; import com.viaversion.nbt.tag.ByteTag;
import com.viaversion.nbt.tag.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.ListTag;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.Types;
@ -55,6 +56,22 @@ public class ItemPacketRewriter1_11 extends ItemRewriter<ClientboundPackets1_9_3
item.setAmount(1); item.setAmount(1);
} }
EntityMappings1_11.toClientItem(item); EntityMappings1_11.toClientItem(item);
if (item == null || item.tag() == null) {
return item;
}
CompoundTag tag = item.tag();
// 1.10 will display item glint if the list tag is present, 1.11+ only if at least one element is present
ListTag enchTag = tag.getListTag("ench");
if (enchTag != null && enchTag.isEmpty()) {
tag.putBoolean(nbtTagName("clearEnch"), true);
CompoundTag dummyTag = new CompoundTag();
dummyTag.putShort("id", Short.MAX_VALUE);
enchTag.add(dummyTag);
}
return item; return item;
} }
@ -63,12 +80,18 @@ public class ItemPacketRewriter1_11 extends ItemRewriter<ClientboundPackets1_9_3
if (item == null) { if (item == null) {
return null; return null;
} }
if (item.tag() != null && item.tag().contains(nbtTagName())) { CompoundTag tag = item.tag();
item.setAmount(item.tag().<ByteTag>removeUnchecked(nbtTagName()).asByte()); if (tag != null) {
if (item.tag().isEmpty()) { if (tag.contains(nbtTagName())) {
item.setAmount(tag.<ByteTag>removeUnchecked(nbtTagName()).asByte());
if (tag.isEmpty()) {
item.setTag(null); item.setTag(null);
} }
} }
if (tag.remove(nbtTagName("clearEnch")) != null) {
tag.put("ench", new ListTag());
}
}
EntityMappings1_11.toServerItem(item); EntityMappings1_11.toServerItem(item);
boolean newItem = item.identifier() >= 218 && item.identifier() <= 234; boolean newItem = item.identifier() >= 218 && item.identifier() <= 234;
newItem |= item.identifier() == 449 || item.identifier() == 450; newItem |= item.identifier() == 449 || item.identifier() == 450;