From 70cd7cfb23a116a2c6af4e058d2697f1e1434ce7 Mon Sep 17 00:00:00 2001 From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> Date: Tue, 26 Mar 2024 21:42:23 -0400 Subject: [PATCH] Deprecate ItemStack#setType --- .../craftbukkit/inventory/CraftItemStack.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java index ffd7ba14be..7228d43d33 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java @@ -429,4 +429,24 @@ public final class CraftItemStack extends ItemStack { static boolean hasItemMeta(net.minecraft.world.item.ItemStack item) { return !(item == null || item.getComponentsPatch().isEmpty()); } + // Paper start - with type + @Override + public ItemStack withType(final Material type) { + if (type == Material.AIR) { + return CraftItemStack.asCraftMirror(null); + } + + final net.minecraft.world.item.ItemStack copy = new net.minecraft.world.item.ItemStack( + CraftItemType.bukkitToMinecraft(type), this.getAmount() + ); + + if (this.handle != null) { + copy.applyComponents(this.handle.getComponentsPatch()); + } + + final CraftItemStack mirrored = CraftItemStack.asCraftMirror(copy); + mirrored.setItemMeta(mirrored.getItemMeta()); + return mirrored; + } + // Paper end }