From d566d164d60ae7ac162273e8aa0671b411c5d9e8 Mon Sep 17 00:00:00 2001 From: lesacar <69954403+lesacar@users.noreply.github.com> Date: Mon, 8 Sep 2025 19:42:52 +0200 Subject: [PATCH] Fix crash when recipe output is module and another crash when player opens equipment grid --- src/api.lua | 12 +++++++++++- src/control.lua | 6 ++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/api.lua b/src/api.lua index 70b20d8..d2e9cfb 100644 --- a/src/api.lua +++ b/src/api.lua @@ -45,7 +45,17 @@ end local function setup_item(item_name, target_quality) if data.raw.item["qrc-"..target_quality.."-"..item_name] then return end - local item = table.deepcopy(data.raw.item[item_name]) + -- Check if the item is a module, since modules are not in data.raw.item but instead in data.raw.module + local item = nil + if string.find(item_name, "-module") then + item = table.deepcopy(data.raw.module[item_name]) + else + item = table.deepcopy(data.raw.item[item_name]) + end + + if not item then + error("Couldn't find item " .. item_name .. " in data.raw!") + end make_icon(item, target_quality) diff --git a/src/control.lua b/src/control.lua index 688ea13..eff1e5e 100644 --- a/src/control.lua +++ b/src/control.lua @@ -89,6 +89,12 @@ script.on_event("on_tick", function() if player.opened then local entity = player.opened if not entity then return end + + -- also check if the player opened the equipment grid to avoid a crash + if entity.object_name == "LuaEquipmentGrid" then + return + end + if entity.type == "assembling-machine" or (entity.type == "entity-ghost" and entity.ghost_type == "assembling-machine") then check_machine_quality(entity) end