I have question about item_request_proxy entities, specifically the following scenario:
1. Player creates a blueprint with locomotive containing fuel item stacks.
2. Player places the blueprint, creating locomotive ghost with item_request property.
3. Construction bot places locomotive, creating locomotive entity and item_request_proxy entity with fuel targeting that locomotive.
4. Mod detects locomotive was created and replaces it with a nearly-identical locomotive entity, copying all parameters so the player doesn't notice the difference.
5. Old item_request_proxy target is invalid, new locomotive does not get fuel. Player notices the difference.
How does Mod know if there was an item_request_proxy targeting the locomotive it replaced? How can it create a new item_request_proxy with the same contents targeting the new locomotive entity?
The revive() function returns the associated item_request_proxy, but only if the script is the one reviving it. For non-script reviving, the on_built and on_robot_built_entity events do not appear to return a reference to any item_request_proxy entities created.
Do I have to search the entire list of entities, or at least item_request_proxy entities, to find out of any of them target the locomotive I am replacing? How would I do that?
Thanks in advance for your help.
How to find item_request_proxy targeting an entity?
Re: How to find item_request_proxy targeting an entity?
I thought that was the answer too, but it appears not. Entity.item_requests is a property of the ghost and item_request_proxy entites, but not built entities. The game crashes if you try to access it on the locomotive itself after it has been revived from a ghost even if it was valid on the ghost.
My mods: Multiple Unit Train Control, Smart Artillery Wagons
Maintainer of Vehicle Wagon 2, Cargo Ships, Honk
Maintainer of Vehicle Wagon 2, Cargo Ships, Honk
Re: How to find item_request_proxy targeting an entity?
Code: Select all
local proxies = locomotive.surface.find_entities_filtered{
name = "item-request-proxy",
force = locomotive.force,
position = locomotive.position
}
for _, proxy in pairs(proxies) do
if proxy.proxy_target == locomotive then
game.print("proxy found")
else
game.print("proxy does not match")
end
end
Re: How to find item_request_proxy targeting an entity?
Thank you, this is just what I need! I was hoping there was a simpler way than searching every time (seems like a hole in the API), but using find_filtered_entities makes it pretty clean.
My mods: Multiple Unit Train Control, Smart Artillery Wagons
Maintainer of Vehicle Wagon 2, Cargo Ships, Honk
Maintainer of Vehicle Wagon 2, Cargo Ships, Honk