From a429b2ad16fd2e65d08917063f5c1fee7abf697b Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sat, 12 Mar 2022 09:26:16 +1100 Subject: [PATCH] #1011: Add Item Unlimited Lifetime APIs By: Gero --- .../bukkit/craftbukkit/entity/CraftItem.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java index d973749181..daf264ca2a 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java @@ -41,12 +41,29 @@ public class CraftItem extends CraftEntity implements Item { item.pickupDelay = Math.min(delay, Short.MAX_VALUE); } + @Override + public void setUnlimitedLifetime(boolean unlimited) { + if (unlimited) { + // See EntityItem#INFINITE_LIFETIME + item.age = Short.MIN_VALUE; + } else { + item.age = getTicksLived(); + } + } + + @Override + public boolean isUnlimitedLifetime() { + return item.age == Short.MIN_VALUE; + } + @Override public void setTicksLived(int value) { super.setTicksLived(value); - // Second field for EntityItem - item.age = value; + // Second field for EntityItem (don't set if lifetime is unlimited) + if (!isUnlimitedLifetime()) { + item.age = value; + } } @Override