From 7c67368f7f6605b4231baba7fea57a37d7fd715e Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Tue, 21 Dec 2021 23:07:15 -0800
Subject: [PATCH] Add API for item entity health (#6514)

---
 build-data/paper.at                           |  3 ++
 .../api/Add-API-for-item-entity-health.patch  | 35 +++++++++++++++++++
 .../Add-API-for-item-entity-health.patch      | 32 +++++++++++++++++
 3 files changed, 70 insertions(+)
 create mode 100644 patches/api/Add-API-for-item-entity-health.patch
 create mode 100644 patches/server/Add-API-for-item-entity-health.patch

diff --git a/build-data/paper.at b/build-data/paper.at
index 73cb1ac04e..da8de1a382 100644
--- a/build-data/paper.at
+++ b/build-data/paper.at
@@ -292,3 +292,6 @@ public net.minecraft.world.item.crafting.RecipeManager byName
 
 # Entity powdered snow API
 public net.minecraft.world.entity.monster.Skeleton inPowderSnowTime
+
+# Add health methods for item entities
+public net.minecraft.world.entity.item.ItemEntity health
diff --git a/patches/api/Add-API-for-item-entity-health.patch b/patches/api/Add-API-for-item-entity-health.patch
new file mode 100644
index 0000000000..ec0789efc9
--- /dev/null
+++ b/patches/api/Add-API-for-item-entity-health.patch
@@ -0,0 +1,35 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Jake Potrebic <jake.m.potrebic@gmail.com>
+Date: Sat, 28 Aug 2021 09:00:35 -0700
+Subject: [PATCH] Add API for item entity health
+
+
+diff --git a/src/main/java/org/bukkit/entity/Item.java b/src/main/java/org/bukkit/entity/Item.java
+index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
+--- a/src/main/java/org/bukkit/entity/Item.java
++++ b/src/main/java/org/bukkit/entity/Item.java
+@@ -0,0 +0,0 @@ public interface Item extends Entity {
+      * @param willAge True if the item should age
+      */
+     public void setWillAge(boolean willAge);
++
++    /**
++     * Gets the health of item stack.
++     * <p>
++     * Currently the default max health is 5.
++     *
++     * @return the health
++     */
++    public int getHealth();
++
++    /**
++     * Sets the health of the item stack. If the value is non-positive
++     * the itemstack's normal "on destroy" functionality will be run.
++     * <p>
++     * Currently, the default max health is 5.
++     *
++     * @param health the health, a non-positive value will destroy the entity
++     */
++    public void setHealth(int health);
+     // Paper end
+ }
diff --git a/patches/server/Add-API-for-item-entity-health.patch b/patches/server/Add-API-for-item-entity-health.patch
new file mode 100644
index 0000000000..531ae43680
--- /dev/null
+++ b/patches/server/Add-API-for-item-entity-health.patch
@@ -0,0 +1,32 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Jake Potrebic <jake.m.potrebic@gmail.com>
+Date: Sat, 28 Aug 2021 09:00:45 -0700
+Subject: [PATCH] Add API for item entity health
+
+
+diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java
+index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
+--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java
++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java
+@@ -0,0 +0,0 @@ public class CraftItem extends CraftEntity implements Item {
+      public void setWillAge(boolean willAge) {
+         item.age = willAge ? 0 : NO_AGE_TIME;
+      }
++
++    @Override
++    public int getHealth() {
++        return item.health;
++    }
++
++    @Override
++    public void setHealth(int health) {
++        if (health <= 0) {
++            item.getItem().onDestroyed(item);
++            item.discard();
++        } else {
++            item.health = health;
++        }
++    }
+     // Paper End
+ 
+     @Override