Hi,
is it somewhere documented in which order the events will be executes inside one mod?
I registered an on_tick and an on_player_tool_inventory_changed event and the on_tick event fired before the other one. I was a little bit surprised because I saved the LuaItemStack of the tool and wanted to access it. To prevent an invalid stack or adjust values based on the used tool, I wanted to use the on_*_changed event. When I removed my iron-axe from the slot, the on_tick event fires and my function tries to access the now invalid stack. So if I save the stack somewhere I have to verify it before each use and makes the on_*_changed useless. I also tested with on_player_main_inventory_changed and on_player_quickbar_inventory_changed, both are executed after on_tick, but the actual action (removing the item from the inventory, caused by the player) was done before on_tick. I would expect the reverse order.
TLDR: please execute on_player_*_inventory_changed before on_tick.
order of events
Re: order of events
The inventory changed events are fired at the end of the tick by design because it's not safe to fire them during the actual changing of that inventory.
Yes, you have to check if something is valid before using it - you always have to do that. The point of the changed events is so you don't have to constantly pole to see if they changed to update your mod state.
Yes, you have to check if something is valid before using it - you always have to do that. The point of the changed events is so you don't have to constantly pole to see if they changed to update your mod state.
If you want to get ahold of me I'm almost always on Discord.
Re: order of events
Thanks for the info, thought I might save some execution time by use the event.