Event for item-request-proxy creation/destruction

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Event for item-request-proxy creation/destruction

Post by Choumiko »

Could we get some event when item-request-proxies are created or destroyed?

I want to sort modules in a specific order and right now i'd have to:
  • watch for all kind of events that could create one
  • save them in global
  • check every X ticks if they are still valid and if they are check again later etc until they are invalid and then i can finally do what the mod is supposed to do
Ideally the events would be created when the proxy is already/still valid, so i can get it's target and modules properties
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

raise on_entity_created for item_request_proxies

Post by Optera »

Problem:
Blueprint containing an assembler with modules

Bots build the assembler, this raises on_robot_built_entity for the assembler, reviving the ghost and replacing the item_requests the ghost held with an item-request-proxy.
The problem now is how to get that item-request-proxy without doing a surface search for every created entity.

While the proxy knows its target entity the target entity does not know its proxy nor does the creation of the proxy raise an event.

Solution:
raise on_entity_created (or similar) when creating an item-request-proxy
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3717
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: raise on_entity_created for item_request_proxies

Post by DaveMcW »

Surface search is not a problem if you only run it in a small area on build events.

Code: Select all

function on_built(event)
  local entity = event.created_entity or event.entity or event.destination
  if not entity or not entity.valid then return end
  for _, proxy in pairs(entity.surface.find_entities_filtered{type="item-request-proxy", position=entity.position}) do
    script.raise_event(defines.events.script_raised_built, {entity = proxy})
  end
end
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: raise on_entity_created for item_request_proxies

Post by Optera »

You are missing the point.
Surface search has to run on EVERY entity creation to catch potential proxies. Creating avoidable overhead.
Arguing that way we should do away with all creation and removal events and just run surface scans in on_tick to catch created entities.

Regarding your snippet:
Its even more efficient to run

Code: Select all

local proxy = entity.surface.find_entity("item-request-proxy", entity.position)
as there should only ever be a single proxy on top of an entity.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5282
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Event for item-request-proxy creation/destruction

Post by Klonan »

Merged with similar topic
Post Reply

Return to “Modding interface requests”