From baaa724595eb917920d12726bf06851f1cee253d Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Sun, 22 Mar 2026 22:05:07 -0400 Subject: [PATCH] Fix crafting turtle: remove self-wrap, use chest push/pull instead MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Same fix as mining turtle — peripheral.wrap(selfName) returns nil on some turtles. Replaced: - selfInv.pushItems(chest, slot) → chest.pullItems(selfName, slot) - selfInv.pullItems(chest, slot, n, dst) → chest.pushItems(selfName, slot, n, dst) --- craftingTurtle.lua | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/craftingTurtle.lua b/craftingTurtle.lua index 6668eb2..0907585 100644 --- a/craftingTurtle.lua +++ b/craftingTurtle.lua @@ -105,13 +105,6 @@ print("[OK] Network name: " .. selfName) modem.open(CRAFT_CHANNEL) print("[OK] Listening on channel " .. CRAFT_CHANNEL) --- Wrap our own inventory peripheral for pullItems/pushItems -local selfInv = peripheral.wrap(selfName) -if not selfInv then - return fatal("[ERR] Cannot wrap own peripheral: " .. selfName .. "\n Make sure the wired modem is connected.") -end - -print("[OK] Self-inventory peripheral ready") print("") print("Waiting for craft commands from master...") print("") @@ -121,15 +114,20 @@ print("") ------------------------------------------------- local function clearInventory(chests) - -- Push all items from all 16 turtle slots back to chests + -- Pull all items from turtle slots into chests (using chest.pullItems) local cleared = 0 for slot = 1, 16 do if turtle.getItemCount(slot) > 0 then for _, chestName in ipairs(chests) do - local ok, n = pcall(selfInv.pushItems, chestName, slot) - if ok and n and n > 0 then - cleared = cleared + n - break + local chest = peripheral.wrap(chestName) + if chest and chest.pullItems then + local ok, n = pcall(chest.pullItems, selfName, slot) + if ok and n and n > 0 then + cleared = cleared + n + if turtle.getItemCount(slot) == 0 then + break + end + end end end end @@ -190,7 +188,13 @@ local function handleCraftCommand(message) print(string.format("[CRAFT] Pulling %s from %s slot %d -> turtle slot %d", itemName, chestName, chestSlot, turtleSlot)) - local ok, n = pcall(selfInv.pullItems, chestName, chestSlot, count, turtleSlot) + local chest = peripheral.wrap(chestName) + if not chest then + print(string.format("[CRAFT] Cannot wrap chest: %s", chestName)) + allPlaced = false + break + end + local ok, n = pcall(chest.pushItems, selfName, chestSlot, count, turtleSlot) if ok and n and n > 0 then placedItems[turtleSlot] = itemName print(string.format("[CRAFT] Placed %s x%d in slot %d", itemName, n, turtleSlot))