From 03f31b993bf0935829b14793818c1e99978b349e Mon Sep 17 00:00:00 2001 From: BillyGalbreath Date: Wed, 20 Oct 2021 14:35:52 -0700 Subject: [PATCH] Add ItemFactory#getMonsterEgg API (#6772) --- build-data/paper.at | 3 ++ .../Add-ItemFactory-getMonsterEgg-API.patch | 25 +++++++++++++++++ .../Add-ItemFactory-getMonsterEgg-API.patch | 28 +++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 patches/api/Add-ItemFactory-getMonsterEgg-API.patch create mode 100644 patches/server/Add-ItemFactory-getMonsterEgg-API.patch diff --git a/build-data/paper.at b/build-data/paper.at index d1527bdbd2..dd2b3c66b3 100644 --- a/build-data/paper.at +++ b/build-data/paper.at @@ -250,3 +250,6 @@ public net.minecraft.world.level.block.entity.BlockEntityType validBlocks # Default entity attributes public net.minecraft.world.entity.ai.attributes.AttributeSupplier instances + +# Add ItemFactory#getMonsterEgg API +public net.minecraft.world.item.SpawnEggItem BY_ID diff --git a/patches/api/Add-ItemFactory-getMonsterEgg-API.patch b/patches/api/Add-ItemFactory-getMonsterEgg-API.patch new file mode 100644 index 0000000000..2d66259834 --- /dev/null +++ b/patches/api/Add-ItemFactory-getMonsterEgg-API.patch @@ -0,0 +1,25 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: William Blake Galbreath +Date: Thu, 14 Oct 2021 12:09:28 -0500 +Subject: [PATCH] Add ItemFactory#getMonsterEgg API + + +diff --git a/src/main/java/org/bukkit/inventory/ItemFactory.java b/src/main/java/org/bukkit/inventory/ItemFactory.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/inventory/ItemFactory.java ++++ b/src/main/java/org/bukkit/inventory/ItemFactory.java +@@ -0,0 +0,0 @@ public interface ItemFactory { + @NotNull + @Deprecated + net.md_5.bungee.api.chat.hover.content.Content hoverContentOf(@NotNull org.bukkit.entity.Entity entity, @NotNull net.md_5.bungee.api.chat.BaseComponent[] customName); ++ ++ /** ++ * Get a monster egg ItemStack from an EntityType ++ * ++ * @param type EntityType ++ * @return ItemStack spawner egg ++ */ ++ @Nullable ++ ItemStack getMonsterEgg(@Nullable org.bukkit.entity.EntityType type); + // Paper end + } diff --git a/patches/server/Add-ItemFactory-getMonsterEgg-API.patch b/patches/server/Add-ItemFactory-getMonsterEgg-API.patch new file mode 100644 index 0000000000..9c4c4c27b3 --- /dev/null +++ b/patches/server/Add-ItemFactory-getMonsterEgg-API.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: William Blake Galbreath +Date: Thu, 14 Oct 2021 12:09:39 -0500 +Subject: [PATCH] Add ItemFactory#getMonsterEgg API + + +diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java ++++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java +@@ -0,0 +0,0 @@ public final class CraftItemFactory implements ItemFactory { + entity.getUniqueId().toString(), + new net.md_5.bungee.api.chat.TextComponent(customName)); + } ++ ++ @Override ++ public ItemStack getMonsterEgg(org.bukkit.entity.EntityType type) { ++ if (type == null) { ++ return null; ++ } ++ String typeId = type.getKey().toString(); ++ net.minecraft.resources.ResourceLocation typeKey = new net.minecraft.resources.ResourceLocation(typeId); ++ net.minecraft.world.entity.EntityType nmsType = net.minecraft.core.Registry.ENTITY_TYPE.get(typeKey); ++ net.minecraft.world.item.SpawnEggItem eggItem = net.minecraft.world.item.SpawnEggItem.BY_ID.get(nmsType); ++ return eggItem == null ? null : new net.minecraft.world.item.ItemStack(eggItem).asBukkitMirror(); ++ } + // Paper end + }