Fixed crash when placing bio gardens

This commit is contained in:
Simon Brodtmann 2025-10-17 11:38:18 +02:00
parent 53114d0c55
commit 970da5fb36

View file

@ -692,12 +692,16 @@ return function(mod_name)
compound_entity.hidden.pole and compound_entity.hidden.pole and
compound_entity.hidden.pole.name then compound_entity.hidden.pole.name then
local wire_reach = prototypes.entity[compound_entity.hidden.pole.name] and local wire_reach = prototypes.entity[compound_entity.hidden.pole.name] and
prototypes.entity[compound_entity.hidden.pole.name].max_wire_distance prototypes.entity[compound_entity.hidden.pole.name].get_max_wire_distance()
if not wire_reach then if not wire_reach then
error("Prototype for hidden pole of Bio gardens doesn't exist!") error("Prototype for hidden pole of Bio gardens doesn't exist!")
end end
pole.disconnect_neighbour() local wire_connector
for _, connector in pairs(pole.get_wire_connectors()) do
wire_connector = connector
connector.disconnect_all()
end
-- Each pole can only have 5 connections. Let's connect to other hidden -- Each pole can only have 5 connections. Let's connect to other hidden
-- poles first! -- poles first!
@ -712,7 +716,7 @@ return function(mod_name)
for n, neighbour in pairs(neighbours or {}) do for n, neighbour in pairs(neighbours or {}) do
if pole ~= neighbour then if pole ~= neighbour then
connected = pole.connect_neighbour(neighbour) connected = wire_connector.connect_to(neighbour)
common.writeDebug("Connected pole %g to %s %g: %s", common.writeDebug("Connected pole %g to %s %g: %s",
{ pole.unit_number, neighbour.name, neighbour.unit_number, connected }) { pole.unit_number, neighbour.name, neighbour.unit_number, connected })
end end
@ -728,7 +732,7 @@ return function(mod_name)
}) })
common.writeDebug("Pole %g has %s neighbours", { pole.unit_number, #neighbours }) common.writeDebug("Pole %g has %s neighbours", { pole.unit_number, #neighbours })
for n, neighbour in pairs(neighbours or {}) do for n, neighbour in pairs(neighbours or {}) do
connected = pole.connect_neighbour(neighbour) connected = wire_connector.connect_to(neighbour)
common.writeDebug("Connected pole %g to neighbour %s (%g): %s", common.writeDebug("Connected pole %g to neighbour %s (%g): %s",
{ pole.unit_number, neighbour.name, neighbour.unit_number, connected }) { pole.unit_number, neighbour.name, neighbour.unit_number, connected })
end end