This commit is contained in:
2025-02-12 20:53:44 +09:00
parent 2a0b4f2bfb
commit 6da76c548e

View File

@@ -109,27 +109,31 @@ local function miner_check(entity)
local pipe_build = {} local pipe_build = {}
if config.fluid and entity.fluidbox and #entity.fluidbox > 0 then if config.fluid and entity.fluidbox and #entity.fluidbox > 0 then
local connections = {} table.insert(pipe_build, { x = 0, y = 0 })
local rh = math.ceil(er / 2) - 1
local r = er + 1
-- Collect all unique pipe connection directions local entities = es.find_entities_filtered{ area = { { ep.x - r, ep.y - r }, { ep.x + r, ep.y + r } }, type = { "mining-drill", "pipe", "pipe-to-ground" } }
for i = 1, #entity.fluidbox do local entities_t = es.find_entities_filtered{ area = { { ep.x - r, ep.y - r }, { ep.x + r, ep.y + r } }, ghost_type = { "pipe", "pipe-to-ground" } }
local box_connections = entity.fluidbox.get_pipe_connections(i)
for _, connection in pairs(box_connections) do table.insert_array(entities, entities_t)
-- Get relative connection position vector
local vec = connection.target_position
-- Normalize to cardinal direction
local direction = { x = (((vec.x > 0.5 and 1) or (vec.x < -0.5 and -1)) or 0), y = (((vec.y > 0.5 and 1) or (vec.y < -0.5 and -1)) or 0) }
-- Convert to string key to prevent duplicates for _, e in pairs(entities) do
local key = direction.x .. "," .. direction.y if (e.position.x > ep.x) and (e.position.y == ep.y) then
if not connections[key] then for h = 1, rh do
connections[key] = true table.insert(pipe_build, { x = h, y = 0 })
-- Calculate pipe positions in this direction
for d = 1, er do
table.insert(pipe_build, { x = direction.x * d, y = direction.y * d })
end end
elseif (e.position.x < ep.x) and (e.position.y == ep.y) then
for h = 1, rh do
table.insert(pipe_build, { x = -h, y = 0 })
end
elseif (e.position.x == ep.x) and (e.position.y > ep.y) then
for h = 1, rh do
table.insert(pipe_build, { x = 0, y = h })
end
elseif (e.position.x == ep.x) and (e.position.y < ep.y) then
for h = 1, rh do
table.insert(pipe_build, { x = 0, y = -h })
end end
end end
end end