diff --git a/src/main/java/carpet/script/CarpetExpression.java b/src/main/java/carpet/script/CarpetExpression.java
index 6af69768..8d5c9cc7 100644
--- a/src/main/java/carpet/script/CarpetExpression.java
+++ b/src/main/java/carpet/script/CarpetExpression.java
@@ -1612,6 +1612,8 @@ public class CarpetExpression
*
Eye height of the entity.
* query(e,'age')
* Age, in ticks, of the entity, i.e. how long it existed.
+ * query(e,'despawn_timer')
+ * For living entities - the number of ticks they fall outside of immediate player presence.
* query(e,'item')
* The item triple (name, count, nbt) if its an item entity, null otherwise
* query(e,'count')
@@ -1707,8 +1709,10 @@ public class CarpetExpression
* modify(e, 'accelerate', x, y, z), modify(e, 'accelerate', l(x, y, z) )
* Adds a vector to the motion vector. Most realistic way to apply a force to an entity.
* modify(e, 'custom_name'), modify(e, 'custom_name', name )
- * modify(e,'pickup_delay')
+ * modify(e, 'pickup_delay')
* Sets a custom pickup delay if the entity argument is an item entity
+ * modify(e, 'despawn_timer')
+ * Sets a custom despawn timer value.
* modify(e, 'dismount')
* Dismounts riding entity.
* modify(e, 'mount', other)
diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java
index 93cbacc7..8ec116ca 100644
--- a/src/main/java/carpet/script/value/EntityValue.java
+++ b/src/main/java/carpet/script/value/EntityValue.java
@@ -225,6 +225,7 @@ public class EntityValue extends Value
put("width", (e, a) -> new NumericValue(e.getDimensions(EntityPose.STANDING).width));
put("eye_height", (e, a) -> new NumericValue(e.getEyeHeight(EntityPose.STANDING)));
put("age", (e, a) -> new NumericValue(e.age));
+ put("despawn_timer", (e, a) -> e instanceof LivingEntity?new NumericValue(((LivingEntity) e).getDespawnCounter()):Value.NULL);
put("item", (e, a) -> (e instanceof ItemEntity)?ListValue.fromItemStack(((ItemEntity) e).getStack()):Value.NULL);
put("count", (e, a) -> (e instanceof ItemEntity)?new NumericValue(((ItemEntity) e).getStack().getCount()):Value.NULL);
put("pickup_delay", (e, a) -> (e instanceof ItemEntity)?new NumericValue(((ItemEntityInterface) e).getPickupDelay()):Value.NULL);
@@ -732,6 +733,14 @@ public class EntityValue extends Value
}
});
+ put("despawn_timer", (e, v) ->
+ {
+ if (e instanceof LivingEntity)
+ {
+ ((LivingEntity) e).setDespawnCounter((int)NumericValue.asNumber(v).getLong());
+ }
+ });
+
put("ai", (e, v) ->
{
if (e instanceof MobEntity)