From 0000000000000000000000000000000000000000 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 diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java index f67b048c3831fcab24acd12249cbd32d386c3ffe..534d3f02ad14ac246ef947a118c07cca81d600dc 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java @@ -711,4 +711,19 @@ public final class CraftItemStack extends ItemStack { static boolean hasItemMeta(net.minecraft.world.item.ItemStack item) { return !(item == null || item.getTag() == null || item.getTag().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 && this.handle.getTag() != null) copy.setTag(this.handle.getTag().copy()); + + final CraftItemStack mirrored = CraftItemStack.asCraftMirror(copy); + mirrored.setItemMeta(mirrored.getItemMeta()); + return mirrored; + } + // Paper end }