gnembon / fabric-carpet

Fabric Carpet
MIT License
1.73k stars 275 forks source link

Scarpet: Let `e~'health'` return a sensible value for item entities #1482

Open James103 opened 2 years ago

James103 commented 2 years ago

Currently (Carpet mod 1.4.79 in Minecraft 1.19), when querying e~'health' on an item entity, the result is always null, despite the item entities having a Health value stored in its NBT (which, unlike living entities, is always an integer).

Workaround: Use e~'nbt':'Health', but this may incur a significant performance hit due to NBT access.

Sample script with workaround: /script run entity_load_handler('item', _(e, new) -> entity_event(e, 'on_removed', _(e) -> (print(player(), e~'nbt':'Health'))));

Sample script, querying health directly: /script run entity_load_handler('item', _(e, new) -> entity_event(e, 'on_removed', _(e) -> (print(player(), e~'health'))));

Use case: I would like to create a Scarpet app that keeps track of how many and what items were burned near a special entity, so as to give the player who placed that special entity credit for the items they burn. To do this, I need to listen to when an item entity is about to be removed, and if so, check whether their Health value is zero or negative, as I don't want items despawning due to age or hopper mechanics to count.

Ghoulboy78 commented 2 years ago

That does make sense, however in ur parcitular case I would be careful cos it may not take into account items dying from explosion damage.