From 435b2426f1e878e4988876f84244fba006771508 Mon Sep 17 00:00:00 2001 From: TehBrian Date: Sat, 17 Aug 2024 06:41:17 -0400 Subject: [PATCH] finish migration to entity tag; fix hash --- ...patch => 1048-add-ItemFrameMeta-API.patch} | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) rename patches/server/{1046-add-ItemFrameMeta-API.patch => 1048-add-ItemFrameMeta-API.patch} (92%) diff --git a/patches/server/1046-add-ItemFrameMeta-API.patch b/patches/server/1048-add-ItemFrameMeta-API.patch similarity index 92% rename from patches/server/1046-add-ItemFrameMeta-API.patch rename to patches/server/1048-add-ItemFrameMeta-API.patch index b5fe14a3ec..e84df44725 100644 --- a/patches/server/1046-add-ItemFrameMeta-API.patch +++ b/patches/server/1048-add-ItemFrameMeta-API.patch @@ -70,14 +70,14 @@ index 5c45946f54e4b16440c15a9165ef85be43e53c84..07ad086bfa77a4b3bcaa188ea65ceb72 map.put(CraftMetaMap.class, Set.of(CraftMetaMap.MAP_COLOR.TYPE, CraftMetaMap.MAP_POST_PROCESSING.TYPE, CraftMetaMap.MAP_ID.TYPE)); diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItemFrame.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItemFrame.java new file mode 100644 -index 0000000000000000000000000000000000000000..b59e7fa357281c6282cf2c7a41c2a6c7c05b06ec +index 0000000000000000000000000000000000000000..b13444c63c37e5c9f4ff969ad473f9280a961332 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItemFrame.java -@@ -0,0 +1,203 @@ +@@ -0,0 +1,206 @@ +// Paper start - add ItemFrameMeta API +package org.bukkit.craftbukkit.inventory; + -+import com.google.common.collect.ImmutableMap; ++import com.google.common.collect.ImmutableMap.Builder; +import com.google.common.collect.Sets; +import io.papermc.paper.inventory.meta.ItemFrameMeta; +import java.io.ByteArrayInputStream; @@ -85,6 +85,7 @@ index 0000000000000000000000000000000000000000..b59e7fa357281c6282cf2c7a41c2a6c7 +import java.io.IOException; +import java.util.Base64; +import java.util.Map; ++import java.util.Objects; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; @@ -157,14 +158,17 @@ index 0000000000000000000000000000000000000000..b59e7fa357281c6282cf2c7a41c2a6c7 + + if (tag.contains(CraftMetaItemFrame.ENTITY_TAG.NBT)) { + this.entityTag = tag.getCompound(CraftMetaItemFrame.ENTITY_TAG.NBT); ++ ++ // fix up legacy item frame metas that did not include entity ID. ++ if (!this.entityTag.contains(ENTITY_ID.NBT)) { ++ this.entityTag.putString(ENTITY_ID.NBT, "minecraft:item_frame"); ++ } + } + } + + @Override + void serializeInternal(Map internalTags) { -+ if (this.entityTag != null && !this.entityTag.isEmpty()) { -+ internalTags.put(CraftMetaItemFrame.ENTITY_TAG.NBT, this.entityTag); -+ } ++ // correctly serialised as entity tag. + } + + @Override @@ -196,7 +200,7 @@ index 0000000000000000000000000000000000000000..b59e7fa357281c6282cf2c7a41c2a6c7 + return false; + } + if (meta instanceof CraftMetaItemFrame that) { -+ return java.util.Objects.equals(this.entityTag, that.entityTag); ++ return Objects.equals(this.entityTag, that.entityTag); + } + return true; + } @@ -215,25 +219,24 @@ index 0000000000000000000000000000000000000000..b59e7fa357281c6282cf2c7a41c2a6c7 + hash = 73 * hash + this.entityTag.hashCode(); + } + -+ return original != hash ? CraftMetaArmorStand.class.hashCode() ^ hash : hash; ++ return original != hash ? CraftMetaItemFrame.class.hashCode() ^ hash : hash; + } + + @Override -+ ImmutableMap.Builder serialize(ImmutableMap.Builder builder) { ++ Builder serialize(Builder builder) { + super.serialize(builder); + -+ if (this.entityTag == null) { -+ return builder; -+ } else { ++ if (this.entityTag != null) { + ByteArrayOutputStream buf = new ByteArrayOutputStream(); + try { -+ NbtIo.writeCompressed(entityTag, buf); ++ NbtIo.writeCompressed(this.entityTag, buf); + } catch (IOException ex) { -+ Logger.getLogger(CraftMetaItem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); ++ Logger.getLogger(CraftMetaItem.class.getName()).log(Level.SEVERE, null, ex); + } + builder.put(ENTITY_TAG.BUKKIT, Base64.getEncoder().encodeToString(buf.toByteArray())); -+ return builder; + } ++ ++ return builder; + } + + @Override @@ -256,12 +259,12 @@ index 0000000000000000000000000000000000000000..b59e7fa357281c6282cf2c7a41c2a6c7 + + @Override + public boolean isFixed() { -+ return this.entityTag != null && this.entityTag.getBoolean(FIXED.NBT); ++ return this.entityTag != null && this.entityTag.contains(FIXED.NBT) && this.entityTag.getBoolean(FIXED.NBT); + } + + @Override + public boolean isInvisible() { -+ return this.entityTag != null && this.entityTag.getBoolean(INVISIBLE.NBT); ++ return this.entityTag != null && this.entityTag.contains(INVISIBLE.NBT) && this.entityTag.getBoolean(INVISIBLE.NBT); + } + + @Override