-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add API for item entity health (#6514)
- Loading branch information
1 parent
2cf6a57
commit 8a21c17
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 0ee072645ecf1bf5feb74de6960947ef76db366e..87dbc00ab565377b8ae0eb6e73799ae6e2e3a376 100644 | ||
--- a/src/main/java/org/bukkit/entity/Item.java | ||
+++ b/src/main/java/org/bukkit/entity/Item.java | ||
@@ -119,5 +119,24 @@ 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 342345eb04d00efb58392ccf209e3c51c1064173..8d56f0ab748373e55c0166b92382c126fe8e5381 100644 | ||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java | ||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java | ||
@@ -85,6 +85,21 @@ 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 |