From f18d78282ddb2f09f92b3095d43fd35630b4fec4 Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 18 Jul 2018 14:01:15 +1000 Subject: [PATCH] SPIGOT-4028: Improve legacy ItemStack conversion --- nms-patches/ItemStack.patch | 2 +- .../inventory/CraftMetaSpawnEgg.java | 2 +- .../bukkit/craftbukkit/util/CraftLegacy.java | 64 ++++++++++--------- 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/nms-patches/ItemStack.patch b/nms-patches/ItemStack.patch index 672002cd40..cddce62869 100644 --- a/nms-patches/ItemStack.patch +++ b/nms-patches/ItemStack.patch @@ -30,7 +30,7 @@ + if (MinecraftServer.getServer() != null) { + NBTTagCompound savedStack = new NBTTagCompound(); + this.save(savedStack); -+ MinecraftServer.getServer().dataConverterManager.update(DataConverterTypes.ITEM_STACK, new Dynamic(DynamicOpsNBT.a, savedStack), -1, CraftMagicNumbers.DATA_VERSION); ++ // MinecraftServer.getServer().dataConverterManager.update(DataConverterTypes.ITEM_STACK, new Dynamic(DynamicOpsNBT.a, savedStack), -1, CraftMagicNumbers.DATA_VERSION); // This changed late in development and hasn't been doing anything. Needs to be fixed. + this.load(savedStack); + } + } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSpawnEgg.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSpawnEgg.java index 892cc10ab4..02b72b8a15 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSpawnEgg.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSpawnEgg.java @@ -63,7 +63,7 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta { if (tag.hasKey(ENTITY_TAG.NBT)) { entityTag = tag.getCompound(ENTITY_TAG.NBT); - MinecraftServer.getServer().dataConverterManager.update(DataConverterTypes.ENTITY, new Dynamic(DynamicOpsNBT.a, entityTag), -1, CraftMagicNumbers.DATA_VERSION); + entityTag = (NBTTagCompound) MinecraftServer.getServer().dataConverterManager.update(DataConverterTypes.ENTITY, new Dynamic(DynamicOpsNBT.a, entityTag), -1, CraftMagicNumbers.DATA_VERSION).getValue(); if (entityTag.hasKey(ENTITY_ID.NBT)) { this.spawnedType = EntityType.fromName(new MinecraftKey(entityTag.getString(ENTITY_ID.NBT)).getKey()); diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftLegacy.java b/src/main/java/org/bukkit/craftbukkit/util/CraftLegacy.java index 4ecba72863..ea2fa6f419 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftLegacy.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftLegacy.java @@ -40,7 +40,7 @@ import org.bukkit.material.MaterialData; @Deprecated public class CraftLegacy { - private static final Map SPAWN_EGGS = new HashMap<>(); + private static final Map SPAWN_EGGS = new HashMap<>(); private static final Set whitelistedStates = new HashSet<>(Arrays.asList("explode", "check_decay", "decayable")); private static final Map materialToItem = new HashMap<>(); private static final Map itemToMaterial = new HashMap<>(); @@ -231,34 +231,36 @@ public class CraftLegacy { } static { - SPAWN_EGGS.put(EntityType.BAT, Material.BAT_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.BLAZE, Material.BLAZE_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.CAVE_SPIDER, Material.CAVE_SPIDER_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.CHICKEN, Material.CHICKEN_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.COW, Material.COW_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.CREEPER, Material.CREEPER_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.ENDERMAN, Material.ENDERMAN_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.ENDERMITE, Material.ENDERMITE_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.GHAST, Material.GHAST_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.GUARDIAN, Material.GUARDIAN_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.HORSE, Material.HORSE_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.MAGMA_CUBE, Material.MAGMA_CUBE_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.MUSHROOM_COW, Material.MOOSHROOM_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.OCELOT, Material.OCELOT_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.PIG, Material.PIG_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.RABBIT, Material.RABBIT_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.SHEEP, Material.SHEEP_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.SHULKER, Material.SHULKER_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.SILVERFISH, Material.SILVERFISH_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.SKELETON, Material.SKELETON_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.SLIME, Material.SLIME_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.SPIDER, Material.SPIDER_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.SQUID, Material.SQUID_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.VILLAGER, Material.VILLAGER_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.WITCH, Material.WITCH_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.WOLF, Material.WOLF_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.PIG_ZOMBIE, Material.ZOMBIE_PIGMAN_SPAWN_EGG); - SPAWN_EGGS.put(EntityType.ZOMBIE, Material.ZOMBIE_SPAWN_EGG); + SPAWN_EGGS.put((byte) 0, Material.PIG_SPAWN_EGG); // Will be fixed by updateMaterial if possible + + SPAWN_EGGS.put((byte) EntityType.BAT.getTypeId(), Material.BAT_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.BLAZE.getTypeId(), Material.BLAZE_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.CAVE_SPIDER.getTypeId(), Material.CAVE_SPIDER_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.CHICKEN.getTypeId(), Material.CHICKEN_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.COW.getTypeId(), Material.COW_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.CREEPER.getTypeId(), Material.CREEPER_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.ENDERMAN.getTypeId(), Material.ENDERMAN_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.ENDERMITE.getTypeId(), Material.ENDERMITE_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.GHAST.getTypeId(), Material.GHAST_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.GUARDIAN.getTypeId(), Material.GUARDIAN_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.HORSE.getTypeId(), Material.HORSE_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.MAGMA_CUBE.getTypeId(), Material.MAGMA_CUBE_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.MUSHROOM_COW.getTypeId(), Material.MOOSHROOM_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.OCELOT.getTypeId(), Material.OCELOT_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.PIG.getTypeId(), Material.PIG_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.RABBIT.getTypeId(), Material.RABBIT_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.SHEEP.getTypeId(), Material.SHEEP_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.SHULKER.getTypeId(), Material.SHULKER_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.SILVERFISH.getTypeId(), Material.SILVERFISH_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.SKELETON.getTypeId(), Material.SKELETON_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.SLIME.getTypeId(), Material.SLIME_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.SPIDER.getTypeId(), Material.SPIDER_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.SQUID.getTypeId(), Material.SQUID_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.VILLAGER.getTypeId(), Material.VILLAGER_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.WITCH.getTypeId(), Material.WITCH_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.WOLF.getTypeId(), Material.WOLF_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.PIG_ZOMBIE.getTypeId(), Material.ZOMBIE_PIGMAN_SPAWN_EGG); + SPAWN_EGGS.put((byte) EntityType.ZOMBIE.getTypeId(), Material.ZOMBIE_SPAWN_EGG); DispenserRegistry.c(); @@ -363,8 +365,8 @@ public class CraftLegacy { } } - for (Map.Entry entry : SPAWN_EGGS.entrySet()) { - MaterialData matData = new MaterialData(Material.LEGACY_MONSTER_EGG, (byte) entry.getKey().getTypeId()); + for (Map.Entry entry : SPAWN_EGGS.entrySet()) { + MaterialData matData = new MaterialData(Material.LEGACY_MONSTER_EGG, entry.getKey()); Item newMaterial = CraftMagicNumbers.getItem(entry.getValue()); materialToItem.put(matData, newMaterial);