Recover spawn egg data from UNSPECIFIC meta.

This commit is contained in:
md_5 2017-01-02 15:29:11 +11:00
parent bf8303f25d
commit a6d8fa2eac
2 changed files with 26 additions and 4 deletions

View File

@ -224,6 +224,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
private static final Set<String> HANDLED_TAGS = Sets.newHashSet();
private NBTTagCompound internalTag;
private final Map<String, NBTBase> unhandledTags = new HashMap<String, NBTBase>();
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<String> keys = tag.c();
internalTag = NBTCompressedStreamTools.a(buf);
deserializeInternal(internalTag);
Set<String> 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) {

View File

@ -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);