Page 1 of 1

Some identifier linking mined entity events with mined item events

Posted: Fri Apr 05, 2019 5:30 pm
by sparr
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

Posted: Fri Apr 05, 2019 5:45 pm
by Bilka
Use case?

Re: Some identifier linking mined entity events with mined item events

Posted: Sun Apr 07, 2019 4:47 am
by sparr
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

Posted: Sat Aug 15, 2020 4:04 am
by sparr
Still wishing for this as I work on rewriting a mod.

Re: Some identifier linking mined entity events with mined item events

Posted: Sat Aug 15, 2020 6:53 am
by Rseding91
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.

Re: Some identifier linking mined entity events with mined item events

Posted: Thu May 02, 2024 6:12 pm
by sparr
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

Posted: Thu May 02, 2024 10:31 pm
by curiosity
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.

Re: Some identifier linking mined entity events with mined item events

Posted: Tue May 07, 2024 3:19 pm
by sparr
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?

Re: Some identifier linking mined entity events with mined item events

Posted: Tue May 07, 2024 4:13 pm
by Rseding91
sparr wrote:
Tue May 07, 2024 3:19 pm
Can the devs say (and document) this as a guarantee?
That is currently how it works and I don't see any plans to change how it works.

Re: Some identifier linking mined entity events with mined item events

Posted: Wed May 08, 2024 7:24 pm
by curiosity
sparr wrote:
Tue May 07, 2024 3:19 pm
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.

Code: Select all

/c for _, entity in pairs(game.player.surface.find_entities_filtered{type = 'tree'}) do game.player.mine_entity(entity) end
Oh, it seems that you will also have to handle the mining of tiles, since that also raises on_player_mined_item.
sparr wrote:
Tue May 07, 2024 3:19 pm
experiments would only be indicative, not proof.
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

Posted: Thu May 09, 2024 8:42 am
by curiosity
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

Posted: Fri May 17, 2024 5:00 pm
by sparr
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

Posted: Fri May 17, 2024 5:54 pm
by curiosity
sparr wrote:
Fri May 17, 2024 5:00 pm
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.
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?