From 59ce10b98604db0a2ca0a60c9046d514328c6127 Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Mon, 16 Mar 2026 00:40:39 -0400 Subject: [PATCH] Enhance crafting error handling and logging in craftItem function --- inventoryManager.lua | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/inventoryManager.lua b/inventoryManager.lua index c7b84e5..9ff2847 100644 --- a/inventoryManager.lua +++ b/inventoryManager.lua @@ -1471,15 +1471,23 @@ end -- since remote turtles may not expose the inventory API (list/pushItems). local function craftItem(recipeIdx) local recipe = CRAFTABLE[recipeIdx] - if not recipe then return false, "Invalid recipe" end - if not craftTurtleName then return false, "No turtle" end - if not networkModem then return false, "No modem" end + if not recipe then + print("[CRAFT] Invalid recipe index: " .. tostring(recipeIdx)) + return false, "Invalid recipe" + end + if not craftTurtleName then + print("[CRAFT] No turtle detected on network") + return false, "No turtle" + end -- Verify the turtle is still on the network if not peripheral.isPresent(craftTurtleName) then + print("[CRAFT] Turtle offline: " .. craftTurtleName) return false, "Turtle offline" end + print(string.format("[CRAFT] Starting craft: %s (turtle: %s)", recipe.output, craftTurtleName)) + activity.crafting = true needsRedraw = true smelterNeedsRedraw = true @@ -1520,18 +1528,26 @@ local function craftItem(recipeIdx) if chest then for slot, slotItem in pairs(chest.list()) do if slotItem.name == itemName then - local n = chest.pushItems(craftTurtleName, slot, 1, turtleSlot) - if n and n > 0 then + print(string.format("[CRAFT] Pushing %s from %s slot %d -> turtle slot %d", itemName, source.chest, slot, turtleSlot)) + local ok, n = pcall(chest.pushItems, craftTurtleName, slot, 1, turtleSlot) + if ok and n and n > 0 then adjustCache(itemName, source.chest, -n) placedItems[turtleSlot] = itemName placed = true + print(string.format("[CRAFT] Placed %s in turtle slot %d", itemName, turtleSlot)) break + elseif not ok then + print(string.format("[CRAFT] pushItems error: %s", tostring(n))) + else + print(string.format("[CRAFT] pushItems returned %s", tostring(n))) end end end end if placed then break end end + else + print(string.format("[CRAFT] Item %s not in catalogue!", itemName)) end if not placed then -- Cleanup: pull placed items back using tracked names