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 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
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?
Re: Some identifier linking mined entity events with mined item events
This is for https://mods.factorio.com/mod/belt-overflow
When a belt is destroyed, I need to recalculate whether any nearby belts might now be places items could back up. All of my calculations for that depend on the destroyed belt being gone, but it isn't when the destroyed event happens, and it is when the mined event happens, so I'd really like to run my check on the mined event.
When a belt is destroyed, I need to recalculate whether any nearby belts might now be places items could back up. All of my calculations for that depend on the destroyed belt being gone, but it isn't when the destroyed event happens, and it is when the mined event happens, so I'd really like to run my check on the mined event.
Re: Some identifier linking mined entity events with mined item events
No, the entity is most definitely gone by the time the destroyed event happens. So just register every belt to that event and problem solved. Not like a tick of delay will make a noticeable difference to the player.
Re: Some identifier linking mined entity events with mined item events
Sorry, I meant on_player_mined_entity, which fires right before the entity is destroyed.
So, using on_entity_destroyed, I could register every belt, and keep a table of their locations, then when one is destroyed I'd know where it was previously located? That's a good idea. A lot of data storage that won't get used, but it would work. That event didn't exist when I created this thread. I'll look into using it!
So, using on_entity_destroyed, I could register every belt, and keep a table of their locations, then when one is destroyed I'd know where it was previously located? That's a good idea. A lot of data storage that won't get used, but it would work. That event didn't exist when I created this thread. I'll look into using it!
Re: Some identifier linking mined entity events with mined item events
...I mentioned it in my first post here, almost two months ago.
If you are concerned with memory use, you can register belts from inside on_player_mined_entity, though of course there are more ways an entity can be destroyed. So pick your poison.
If you are concerned with memory use, you can register belts from inside on_player_mined_entity, though of course there are more ways an entity can be destroyed. So pick your poison.
Re: Some identifier linking mined entity events with mined item events
How can I handle the situation where an entity gets moved, like with Picker Dollies or another mod or script?
Re: Some identifier linking mined entity events with mined item events
Picker Dollies will raise a custom event when it's moving an entity. From its info page:
Other mods that move entities around should have their own custom events.In your mods on_load and on_init events add:
The dolly moved event returns a table with the following the information:Code: Select all
if remote.interfaces["PickerDollies"] and remote.interfaces["PickerDollies"]["dolly_moved_entity_id"] then script.on_event(remote.call("PickerDollies", "dolly_moved_entity_id"), your_function_to_update_the_entity) end
In addition a remote api to disallow moving of an entity is available:Code: Select all
{ player_index = player_index, -- The index of the player who moved the entity moved_entity = entity, -- The entity that was moved start_pos = position -- The position that the entity was moved from }
Code: Select all
if remote.interfaces["PickerDollies"] and remote.interfaces["PickerDollies"]["add_blacklist_name"] then remote.call("PickerDollies", "add_blacklist_name", "name-of-your-entity") end
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!