Paper/patches/server/0730-Add-API-for-item-entity-health.patch
2023-12-06 15:09:14 -05:00

35 lines
1.2 KiB
Diff

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
== AT ==
public net.minecraft.world.entity.item.ItemEntity health
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java
index cbdac5a439795d429a1364a7eafc4783cff51d54..b1bbab951ef9a3d2bd98cc54665ba824263542eb 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java
@@ -98,6 +98,21 @@ public class CraftItem extends CraftEntity implements Item {
public void setWillAge(boolean willAge) {
this.getHandle().age = willAge ? 0 : NO_AGE_TIME;
}
+
+ @Override
+ public int getHealth() {
+ return this.getHandle().health;
+ }
+
+ @Override
+ public void setHealth(int health) {
+ if (health <= 0) {
+ this.getHandle().getItem().onDestroyed(this.getHandle());
+ this.getHandle().discard();
+ } else {
+ this.getHandle().health = health;
+ }
+ }
// Paper End
@Override