From 9f5968f8b23a36bf9334c5f0820ecb80a5466e8e Mon Sep 17 00:00:00 2001 From: notnotmelon Date: Wed, 10 Jan 2024 16:25:31 -0600 Subject: [PATCH] add some extra null checks in biofluid --- changelog.txt | 1 + migrations/biofluid.lua | 5 +++++ scripts/biofluid/biofluid.lua | 24 +++++++++++++----------- scripts/biofluid/network-builder.lua | 1 + 4 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 migrations/biofluid.lua diff --git a/changelog.txt b/changelog.txt index f2a9dd5a..e020df11 100644 --- a/changelog.txt +++ b/changelog.txt @@ -7,6 +7,7 @@ Date: ??? - Nerfed scrondrix path 1. No longer grants bonus cubs - Buffed scrondrix path 2. Multiplies meat by 3x instead of 5x. No more -20% speed downgrade - Nerfed composter path 1. Dried biomass amount reduced 12 -> 4 + - Fixed improper migrations to new biofluid system causing crashes (https://github.com/pyanodon/pybugreports/issues/367) --------------------------------------------------------------------------------------------------- Version: 2.1.13 Date: 2024-1-8 diff --git a/migrations/biofluid.lua b/migrations/biofluid.lua new file mode 100644 index 00000000..61d48cdd --- /dev/null +++ b/migrations/biofluid.lua @@ -0,0 +1,5 @@ +--for _, surface in pairs(game.surfaces) do + --for _, pipe in pairs(surface.find_entities_filtered{name = {'vessel', 'bioport'}}) do + --pipe.destroy() + --end +--end \ No newline at end of file diff --git a/scripts/biofluid/biofluid.lua b/scripts/biofluid/biofluid.lua index 612ab592..608b8fee 100644 --- a/scripts/biofluid/biofluid.lua +++ b/scripts/biofluid/biofluid.lua @@ -364,17 +364,19 @@ local function find_new_home(biorobot_data, network_data) local home local min_robot_count = 999 for unit_number, bioport in pairs(network_data.bioports) do - local bioport_data = global.biofluid_bioports[bioport.unit_number] - if unit_number ~= old_home and bioport.valid and bioport_data then - local robot_count = bioport.get_inventory(INPUT_INVENTORY).get_item_count(biorobot_data.entity.name) - if robot_count < 6 then - home = bioport - biorobot_data.bioport = unit_number - break - elseif robot_count < min_robot_count then - min_robot_count = robot_count - home = bioport - biorobot_data.bioport = unit_number + if bioport.valid then + local bioport_data = global.biofluid_bioports[bioport.unit_number] + if unit_number ~= old_home and bioport.valid and bioport_data then + local robot_count = bioport.get_inventory(INPUT_INVENTORY).get_item_count(biorobot_data.entity.name) + if robot_count < 6 then + home = bioport + biorobot_data.bioport = unit_number + break + elseif robot_count < min_robot_count then + min_robot_count = robot_count + home = bioport + biorobot_data.bioport = unit_number + end end end end diff --git a/scripts/biofluid/network-builder.lua b/scripts/biofluid/network-builder.lua index 420cf8dd..9412c5d3 100644 --- a/scripts/biofluid/network-builder.lua +++ b/scripts/biofluid/network-builder.lua @@ -194,6 +194,7 @@ function Biofluid.built_pipe(entity, update_graphics) end function Biofluid.is_looking_at_us(entity, connection, network_positions) + if not entity.valid then return nil end if not network_positions then network_positions = Biofluid.network_positions(entity.surface_index) end