Fix mining turtle: use pull instead of push to avoid self-wrap failure
peripheral.wrap(selfName) can return nil on some turtles even when connected. Switch to wrapping the remote chest and calling chest.pullItems(selfName, slot) instead.
This commit is contained in:
@@ -98,12 +98,6 @@ if not modem or not selfName then
|
|||||||
return fatal("[ERR] No wired modem found!\n Attach a wired modem to the turtle\n and connect it to the network.")
|
return fatal("[ERR] No wired modem found!\n Attach a wired modem to the turtle\n and connect it to the network.")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Wrap our own inventory peripheral for 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] Modem: " .. modemSide)
|
print("[OK] Modem: " .. modemSide)
|
||||||
print("[OK] Network name: " .. selfName)
|
print("[OK] Network name: " .. selfName)
|
||||||
print("[OK] Mine interval: " .. MINE_INTERVAL .. "s")
|
print("[OK] Mine interval: " .. MINE_INTERVAL .. "s")
|
||||||
@@ -128,6 +122,9 @@ end
|
|||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
-- Dump inventory into networked storage
|
-- Dump inventory into networked storage
|
||||||
|
-- Uses pull approach: wrap the remote chest and call
|
||||||
|
-- chest.pullItems(selfName, slot) — avoids needing
|
||||||
|
-- to wrap the turtle's own peripheral.
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
|
|
||||||
local function dumpInventory()
|
local function dumpInventory()
|
||||||
@@ -141,11 +138,14 @@ local function dumpInventory()
|
|||||||
for slot = 1, 16 do
|
for slot = 1, 16 do
|
||||||
if slot ~= FUEL_SLOT and turtle.getItemCount(slot) > 0 then
|
if slot ~= FUEL_SLOT and turtle.getItemCount(slot) > 0 then
|
||||||
for _, chestName in ipairs(chests) do
|
for _, chestName in ipairs(chests) do
|
||||||
local ok, n = pcall(selfInv.pushItems, chestName, slot)
|
local chest = peripheral.wrap(chestName)
|
||||||
if ok and n and n > 0 then
|
if chest and chest.pullItems then
|
||||||
totalPushed = totalPushed + n
|
local ok, n = pcall(chest.pullItems, selfName, slot)
|
||||||
if turtle.getItemCount(slot) == 0 then
|
if ok and n and n > 0 then
|
||||||
break -- slot empty, move to next
|
totalPushed = totalPushed + n
|
||||||
|
if turtle.getItemCount(slot) == 0 then
|
||||||
|
break -- slot empty, move to next
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user