Paper/patches/server/0752-Add-API-for-item-entity-health.patch

35 lines
1.1 KiB
Diff
Raw Normal View History

2021-12-22 08:07:15 +01:00
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
2021-12-22 08:07:15 +01:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java
index 27e961653dc66fbe8d5421eef04260b91ca410f4..e9946edf568db010e4ccb9fe7755709ed7b8310f 100644
2021-12-22 08:07:15 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java
@@ -102,6 +102,21 @@ public class CraftItem extends CraftEntity implements Item {
2021-12-22 08:07:15 +01:00
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