Fix item extract critera

This commit is contained in:
Gabriel Tofvesson 2024-09-25 10:30:42 +00:00
parent e5e115bd19
commit c5034f8964

View File

@ -1,4 +1,3 @@
local FILE_CACHE = ".storage.cache"
local STORAGE_NODE_NAME = "minecraft:trapped_chest"
local STORAGE_STORE_PREFIX = "minecraft:chest_"
local node = peripheral.find(STORAGE_NODE_NAME)
@ -243,7 +242,7 @@ function Cache:insertStack(nodeSlot)
local slotCap = math.min(slot.maxCount - slot.count, detail.count - count)
local result, change = pcall(node.pushItems, slot.chest, nodeSlot, slotCap, slot.slot)
if not result then
print("Slot insert error for chest \""..slot.chest.."\"! Make sure it's still attached to the controller")
print("Slot insert error for chest \""..slot.chest.."\"! Make sure it's still attached to the controller: "..change)
else
if change == slot.count then
self:reloadSlot(slot.chest, slot.slot)
@ -266,14 +265,14 @@ function Cache:extractStack(detail)
local count = 0
for index,slot in ipairs(foundSlots) do
if count == detail.count then
if detail ~= nil and count == detail.count then
break
end
local slotCap = math.min(slot.maxCount - slot.count, detail.count - count)
local slotCap = (detail == nil or detail.count == nil) and slot.count or math.min(slot.count, detail.count)
local result, change = pcall(node.pullItems, slot.chest, slot.slot, slotCap)
if not result then
print("Slot extract error for chest \""..slot.chest.."\"! Make sure it's still attached to the controller")
print("Slot extract error for chest \""..slot.chest.."\"! Make sure it's still attached to the controller: "..change)
else
if change == slot.count then
self:reloadSlot(slot.chest, slot.slot)
@ -284,7 +283,7 @@ function Cache:extractStack(detail)
end
end
return (detail.count == nil) or (detail.count == count), count
return (detail == nil or detail.count == nil) or (detail.count == count), count
end
local function clone(o)