Help w/ inserters, drop target, etc.
Posted: Mon Nov 27, 2023 1:13 am
I'm working on a quality-of-life mod; first Factorio mod, not very experienced on Lua.
Goal: When you drop a logistic storage container (over an existing chest) it will check to see if there's an inserter for the container, and if that inserter takes from an assembler. If so, the mod will set the filter for the container to match the assembler's output. Further, it will remove the inventory block, if any, and replace it with a circuit network override on the inserter (i.e., "blue belts < 1000").
Just getting started, but when I'm having trouble with inserters.
That finds the inserters, but the drop_target of each inserter is nil. I suspect its an order-of-operations issue, in that built-in logic hasn't recomputed that the inserter drops into the just-built container entity.
I think I can use drop_position and compare it to box.position, but I'm wondering if there's a correct way to do this, i.e., a built-in function on the LuaEntity that I'm missing?
Goal: When you drop a logistic storage container (over an existing chest) it will check to see if there's an inserter for the container, and if that inserter takes from an assembler. If so, the mod will set the filter for the container to match the assembler's output. Further, it will remove the inventory block, if any, and replace it with a circuit network override on the inserter (i.e., "blue belts < 1000").
Just getting started, but when I'm having trouble with inserters.
Code: Select all
script.on_event(defines.events.on_built_entity, function(event)
local box = event.created_entity
local player = game.get_player(event.player_index)
local surface = player.surface
local inserters = surface.find_entities_filtered {
-- TODO: Maybe entity.collision_box would work instead
position = box.position,
type = "inserter",
radius = 1.0
}
I think I can use drop_position and compare it to box.position, but I'm wondering if there's a correct way to do this, i.e., a built-in function on the LuaEntity that I'm missing?