3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-16 04:50:08 +01:00

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

Dieser Commit ist enthalten in:
EnZaXD 2024-09-23 19:24:46 +02:00 committet von GitHub
Ursprung a0a2794291
Commit 5287d4fb4f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194

Datei anzeigen

@ -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,10 +80,16 @@ 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.setTag(null); item.setAmount(tag.<ByteTag>removeUnchecked(nbtTagName()).asByte());
if (tag.isEmpty()) {
item.setTag(null);
}
}
if (tag.remove(nbtTagName("clearEnch")) != null) {
tag.put("ench", new ListTag());
} }
} }
EntityMappings1_11.toServerItem(item); EntityMappings1_11.toServerItem(item);