From 2089697232c3112990abeecacf070d2494c6c32f Mon Sep 17 00:00:00 2001
From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com>
Date: Sat, 6 Apr 2024 23:26:56 +0200
Subject: [PATCH] Don't throw NPE for unplaced blockstate on #getDrops (#10366)

---
 patches/api/Add-getDrops-to-BlockState.patch    | 11 +++++++++--
 patches/server/Add-getDrops-to-BlockState.patch | 11 +----------
 2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/patches/api/Add-getDrops-to-BlockState.patch b/patches/api/Add-getDrops-to-BlockState.patch
index 8543995b31..4262842642 100644
--- a/patches/api/Add-getDrops-to-BlockState.patch
+++ b/patches/api/Add-getDrops-to-BlockState.patch
@@ -19,9 +19,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +     * Returns an immutable list of items which would drop by destroying this block state.
 +     *
 +     * @return an immutable list of dropped items for the block state
++     * @throws IllegalStateException if this block state is not placed
 +     */
 +    @NotNull
-+    java.util.@org.jetbrains.annotations.Unmodifiable Collection<org.bukkit.inventory.ItemStack> getDrops();
++    default java.util.@org.jetbrains.annotations.Unmodifiable Collection<org.bukkit.inventory.ItemStack> getDrops() {
++        return this.getDrops(null);
++    }
 +
 +    /**
 +     * Returns an immutable list of items which would drop by destroying this block state
@@ -29,9 +32,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +     *
 +     * @param tool The tool or item in hand used for digging
 +     * @return an immutable list of dropped items for the block state
++     * @throws IllegalStateException if this block state is not placed
 +     */
 +    @NotNull
-+    java.util.@org.jetbrains.annotations.Unmodifiable Collection<org.bukkit.inventory.ItemStack> getDrops(@Nullable org.bukkit.inventory.ItemStack tool);
++    default java.util.@org.jetbrains.annotations.Unmodifiable Collection<org.bukkit.inventory.ItemStack> getDrops(@Nullable org.bukkit.inventory.ItemStack tool) {
++        return this.getDrops(tool, null);
++    }
 +
 +    /**
 +     * Returns an immutable list of items which would drop by the entity destroying this
@@ -40,6 +46,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +     * @param tool The tool or item in hand used for digging
 +     * @param entity the entity destroying the block
 +     * @return an immutable list of dropped items for the block state
++     * @throws IllegalStateException if this block state is not placed
 +     */
 +    @NotNull
 +    java.util.@org.jetbrains.annotations.Unmodifiable Collection<org.bukkit.inventory.ItemStack> getDrops(@Nullable org.bukkit.inventory.ItemStack tool, @Nullable org.bukkit.entity.Entity entity);
diff --git a/patches/server/Add-getDrops-to-BlockState.patch b/patches/server/Add-getDrops-to-BlockState.patch
index a7d8c4fba6..34c3761d91 100644
--- a/patches/server/Add-getDrops-to-BlockState.patch
+++ b/patches/server/Add-getDrops-to-BlockState.patch
@@ -16,17 +16,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
      }
 +
 +    @Override
-+    public java.util.Collection<org.bukkit.inventory.ItemStack> getDrops() {
-+        return this.getDrops(null);
-+    }
-+
-+    @Override
-+    public java.util.Collection<org.bukkit.inventory.ItemStack> getDrops(org.bukkit.inventory.ItemStack item) {
-+        return this.getDrops(item, null);
-+    }
-+
-+    @Override
 +    public java.util.Collection<org.bukkit.inventory.ItemStack> getDrops(org.bukkit.inventory.ItemStack item, org.bukkit.entity.Entity entity) {
++        this.requirePlaced();
 +        net.minecraft.world.item.ItemStack nms = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(item);
 +
 +        // Modelled off EntityHuman#hasBlock