From a6d8fa2eac1d7a51c70229f84edea9ea90ba4fd0 Mon Sep 17 00:00:00 2001 From: md_5 Date: Mon, 2 Jan 2017 15:29:11 +1100 Subject: Recover spawn egg data from UNSPECIFIC meta. --- .../org/bukkit/craftbukkit/inventory/CraftMetaItem.java | 14 ++++++++++---- .../bukkit/craftbukkit/inventory/CraftMetaSpawnEgg.java | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java index bb764444..09e2d246 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java @@ -224,6 +224,7 @@ class CraftMetaItem implements ItemMeta, Repairable { private static final Set HANDLED_TAGS = Sets.newHashSet(); + private NBTTagCompound internalTag; private final Map unhandledTags = new HashMap(); CraftMetaItem(CraftMetaItem meta) { @@ -245,6 +246,11 @@ class CraftMetaItem implements ItemMeta, Repairable { this.hideFlag = meta.hideFlag; this.unbreakable = meta.unbreakable; this.unhandledTags.putAll(meta.unhandledTags); + + this.internalTag = meta.internalTag; + if (this.internalTag != null) { + deserializeInternal(internalTag); + } } CraftMetaItem(NBTTagCompound tag) { @@ -388,12 +394,12 @@ class CraftMetaItem implements ItemMeta, Repairable { if (internal != null) { ByteArrayInputStream buf = new ByteArrayInputStream(Base64.decodeBase64(internal)); try { - NBTTagCompound tag = NBTCompressedStreamTools.a(buf); - deserializeInternal(tag); - Set keys = tag.c(); + internalTag = NBTCompressedStreamTools.a(buf); + deserializeInternal(internalTag); + Set keys = internalTag.c(); for (String key : keys) { if (!getHandledTags().contains(key)) { - unhandledTags.put(key, tag.get(key)); + unhandledTags.put(key, internalTag.get(key)); } } } catch (IOException ex) { diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSpawnEgg.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSpawnEgg.java index 22199ed7..b98c02ff 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSpawnEgg.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSpawnEgg.java @@ -3,7 +3,9 @@ package org.bukkit.craftbukkit.inventory; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap.Builder; import java.util.Map; +import net.minecraft.server.DataConverterTypes; import net.minecraft.server.MinecraftKey; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.NBTTagCompound; import org.bukkit.Material; import org.bukkit.configuration.serialization.DelegateDeserialization; @@ -50,6 +52,20 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta { setSpawnedType(EntityType.fromName(entityType)); } + @Override + void deserializeInternal(NBTTagCompound tag) { + super.deserializeInternal(tag); + + if (tag.hasKey(ENTITY_TAG.NBT)) { + entityTag = tag.getCompound(ENTITY_TAG.NBT); + MinecraftServer.getServer().getDataConverterManager().a(DataConverterTypes.ENTITY, entityTag); // PAIL: convert + + if (entityTag.hasKey(ENTITY_ID.NBT)) { + this.spawnedType = EntityType.fromName(new MinecraftKey(entityTag.getString(ENTITY_ID.NBT)).a()); // PAIL: rename + } + } + } + @Override void applyToItem(NBTTagCompound tag) { super.applyToItem(tag); -- cgit v1.2.3