Code: Select all
function replace_underground_belt (old_underground_belt_entity, new_underground_belt_name)
local data = old_underground_belt_entity
-- http://lua-api.factorio.com/latest/LuaSurface.html#LuaSurface.create_entity
surface.create_entity{name=new_underground_belt_name, position=data.position, direction=data.direction, force=data.force, fast_replace=true, 'underground-belt' = data.input_or_output}
-- http://lua-api.factorio.com/latest/LuaEntity.html#LuaEntity.neighbours
local neighbours = data.neighbours -- When called on an underground transport belt, this is the other end of the underground belt connection, or nil if none.
data = neighbours[1]
surface.create_entity{name=new_underground_belt_name, position=data.position, direction=data.direction, force=data.force, fast_replace=true, 'underground-belt' = data.input_or_output}
end