Some identifier linking mined entity events with mined item events
Some identifier linking mined entity events with mined item events
When on_player_mined_item fires, there seems to be no information available about the entity that was mined because it is gone. I would like for there to be some identifier in on_player_mined_entity and on_player_mined_item that allows them to be matched up, so that I can save some info about the entity while it still exists, to be referred to shortly afterward.
Re: Some identifier linking mined entity events with mined item events
Use case?
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Re: Some identifier linking mined entity events with mined item events
After the entity is removed I need to check the game state for changed belt connections, changed pipe connections, changed rail segments, etc.
Re: Some identifier linking mined entity events with mined item events
Still wishing for this as I work on rewriting a mod.
Re: Some identifier linking mined entity events with mined item events
Just don't use that event. The https://lua-api.factorio.com/latest/eve ... ned_entity event contains a LuaInventory with all the things that are going to end up in the event anyway.
If you want to get ahold of me I'm almost always on Discord.
Re: Some identifier linking mined entity events with mined item events
Yes, but when that event fires the entity is still in the world, so none of my checks are valid yet. I need to run my checks after the entity is destroyed, and on_player_mined_item seems to be the only event that triggers at that point.
Re: Some identifier linking mined entity events with mined item events
Can sequences of these two events be interleaved? Doesn't seem so. Then it seems simple to match the events: all you need is a stack and a tick number.
There is also on_entity_destroyed.
There is also on_entity_destroyed.
Re: Some identifier linking mined entity events with mined item events
Are you suggesting that when I mine two entities in the same tick I will always get the mined entity event for one, then the mined item event for the same one, then the mined entity event for the other, then the mined item event for the other? I'm not sure how to test this assumption; experiments would only be indicative, not proof.
Can the devs say (and document) this as a guarantee?
Can the devs say (and document) this as a guarantee?
Re: Some identifier linking mined entity events with mined item events
That is currently how it works and I don't see any plans to change how it works.
If you want to get ahold of me I'm almost always on Discord.
Re: Some identifier linking mined entity events with mined item events
sparr wrote: ↑Tue May 07, 2024 3:19 pmAre you suggesting that when I mine two entities in the same tick I will always get the mined entity event for one, then the mined item event for the same one, then the mined entity event for the other, then the mined item event for the other? I'm not sure how to test this assumption
experiments would only be indicative, not proof.
Code: Select all
/c for _, entity in pairs(game.player.surface.find_entities_filtered{type = 'tree'}) do game.player.mine_entity(entity) end
You must assume there is some internal logic to the game, other way lies madness.
Re: Some identifier linking mined entity events with mined item events
Hmm... maybe this isn't so doable, after all. A mod might do something crazy to interrupt the mining process (destroy the entity, ban the player etc.), the item event might never be emitted. Best is, I guess, to check the top entity on the stack to see if it has been destroyed already, since that and not a 1-to-1 event matching is your real goal.
Re: Some identifier linking mined entity events with mined item events
To be clear, my "real goal" here is to be able to identify what entity was just destroyed as soon as possible after the entity gets destroyed.
Re: Some identifier linking mined entity events with mined item events
Is it your mod's entity or some arbitrary one? Because in the latter case another mod can always screw you over and it will be within reason. Either you don't get any event by the time the entity is destroyed or it's destroyed after you decided it's not.
So what's your actual real goal? Why are you unsatisfied with the intended ways to detect this?