Inventory Last Updated Tick API
Posted: Mon Mar 24, 2025 12:59 pm
Background:
Currently, there is no built-in way to determine whether the contents of an entity's inventory have changed since the last game tick. Modders must manually track inventory states and compare them each tick, which can be inefficient for large-scale monitoring.
Recommendation:
Introduce a new property to the LuaEntity object that provides the last tick when the entity's inventory was modified.
API Addition:
-- Returns the last game tick when this entity's inventory was modified.
LuaEntity.last_inventory_update_tick :: uint (read-only)
Details:
This property would be updated whenever an item is added or removed from any of the entity’s inventories (main, input, output, fuel, etc.).
It would allow modders to efficiently track inventory changes without needing to compare inventory states manually.
Works similarly to last_user, storing the last interaction tick for reference.
If the inventory has never been modified, it could return when the object was placed.
Use Case:
Instead of iterating over thousands of chests and comparing inventory contents every tick, modders could simply check:
if entity.last_inventory_update_tick == game.tick then
-- Inventory changed this tick, trigger logic
end
This addition would provide a much-needed optimization for modders working with logistics and circuit network integrations.
Currently, there is no built-in way to determine whether the contents of an entity's inventory have changed since the last game tick. Modders must manually track inventory states and compare them each tick, which can be inefficient for large-scale monitoring.
Recommendation:
Introduce a new property to the LuaEntity object that provides the last tick when the entity's inventory was modified.
API Addition:
-- Returns the last game tick when this entity's inventory was modified.
LuaEntity.last_inventory_update_tick :: uint (read-only)
Details:
This property would be updated whenever an item is added or removed from any of the entity’s inventories (main, input, output, fuel, etc.).
It would allow modders to efficiently track inventory changes without needing to compare inventory states manually.
Works similarly to last_user, storing the last interaction tick for reference.
If the inventory has never been modified, it could return when the object was placed.
Use Case:
Instead of iterating over thousands of chests and comparing inventory contents every tick, modders could simply check:
if entity.last_inventory_update_tick == game.tick then
-- Inventory changed this tick, trigger logic
end
This addition would provide a much-needed optimization for modders working with logistics and circuit network integrations.