From 11f5158eaa3afd344632fa19bde9508e94967a4b Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sat, 18 Mar 2023 10:32:03 -0700 Subject: [PATCH] Fix SpawnEggMeta#get/setSpawnedType (#8907) --- ...-Fix-SpawnEggMeta-get-setSpawnedType.patch | 47 +++++++++++++++++++ ...-Fix-SpawnEggMeta-get-setSpawnedType.patch | 42 +++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 patches/api/0419-Fix-SpawnEggMeta-get-setSpawnedType.patch create mode 100644 patches/server/0966-Fix-SpawnEggMeta-get-setSpawnedType.patch diff --git a/patches/api/0419-Fix-SpawnEggMeta-get-setSpawnedType.patch b/patches/api/0419-Fix-SpawnEggMeta-get-setSpawnedType.patch new file mode 100644 index 0000000000..4014e17083 --- /dev/null +++ b/patches/api/0419-Fix-SpawnEggMeta-get-setSpawnedType.patch @@ -0,0 +1,47 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jake Potrebic +Date: Sun, 26 Feb 2023 07:14:19 -0800 +Subject: [PATCH] Fix SpawnEggMeta#get/setSpawnedType + + +diff --git a/src/main/java/org/bukkit/inventory/meta/SpawnEggMeta.java b/src/main/java/org/bukkit/inventory/meta/SpawnEggMeta.java +index 9ae84de43018e2dc9df5e1a56244d8812c2ffbb8..c190dff53e18994c93c35b6a9502cba38e6886ed 100644 +--- a/src/main/java/org/bukkit/inventory/meta/SpawnEggMeta.java ++++ b/src/main/java/org/bukkit/inventory/meta/SpawnEggMeta.java +@@ -15,7 +15,7 @@ public interface SpawnEggMeta extends ItemMeta { + * @return The entity type. May be null for implementation specific default. + * @deprecated different types are different items + */ +- @Deprecated ++ @Deprecated(forRemoval = true) // Paper + @Contract("-> fail") + EntityType getSpawnedType(); + +@@ -26,10 +26,26 @@ public interface SpawnEggMeta extends ItemMeta { + * default. + * @deprecated different types are different items + */ +- @Deprecated ++ @Deprecated(forRemoval = true) // Paper + @Contract("_ -> fail") + void setSpawnedType(EntityType type); + ++ // Paper start ++ /** ++ * Get the custom type of entity this egg will spawn. ++ * ++ * @return the entity type or null if no custom type is set ++ */ ++ @org.jetbrains.annotations.Nullable EntityType getCustomSpawnedType(); ++ ++ /** ++ * Set the custom type of entity this egg will spawn. ++ * ++ * @param type the entity type or null to clear the custom type ++ */ ++ void setCustomSpawnedType(@org.jetbrains.annotations.Nullable EntityType type); ++ // Paper end ++ + @NotNull + @Override + SpawnEggMeta clone(); diff --git a/patches/server/0966-Fix-SpawnEggMeta-get-setSpawnedType.patch b/patches/server/0966-Fix-SpawnEggMeta-get-setSpawnedType.patch new file mode 100644 index 0000000000..4c90082c28 --- /dev/null +++ b/patches/server/0966-Fix-SpawnEggMeta-get-setSpawnedType.patch @@ -0,0 +1,42 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jake Potrebic +Date: Thu, 23 Feb 2023 13:19:13 -0800 +Subject: [PATCH] Fix SpawnEggMeta#get/setSpawnedType + + +diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSpawnEgg.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSpawnEgg.java +index 2f65ce5d63ea4ad3a0b1b8fa47efa97b6641ef20..3ab43aab043ae59e541f708c8558ddf9bdd82f84 100644 +--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSpawnEgg.java ++++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSpawnEgg.java +@@ -216,6 +216,31 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta { + throw new UnsupportedOperationException("Must change item type to set spawned type"); + } + ++ // Paper start ++ @Override ++ public EntityType getCustomSpawnedType() { ++ return java.util.Optional.ofNullable(this.entityTag) ++ .map(tag -> tag.getString(ENTITY_ID.NBT)) ++ .flatMap(net.minecraft.world.entity.EntityType::byString) ++ .map(org.bukkit.craftbukkit.util.CraftMagicNumbers::getEntityType) ++ .orElse(null); ++ } ++ ++ @Override ++ public void setCustomSpawnedType(final EntityType type) { ++ if (type == null) { ++ if (this.entityTag != null) { ++ this.entityTag.remove(ENTITY_ID.NBT); ++ } ++ } else { ++ if (this.entityTag == null) { ++ this.entityTag = new CompoundTag(); ++ } ++ this.entityTag.putString(ENTITY_ID.NBT, type.key().toString()); ++ } ++ } ++ // Paper end ++ + @Override + boolean equalsCommon(CraftMetaItem meta) { + if (!super.equalsCommon(meta)) {