summaryrefslogtreecommitdiff
path: root/inv_utils.lua
diff options
context:
space:
mode:
Diffstat (limited to 'inv_utils.lua')
-rw-r--r--inv_utils.lua42
1 files changed, 41 insertions, 1 deletions
diff --git a/inv_utils.lua b/inv_utils.lua
index 9a6e280..3a3feed 100644
--- a/inv_utils.lua
+++ b/inv_utils.lua
@@ -16,6 +16,46 @@ local function hasItemsInTurtle()
return false
end
+local function fillTurtle()
+ local success = true
+ turtle.select(1)
+ while success do
+ success = turtle.suck()
+ end
+end
+
+local function emptyTurtle()
+ for ii = 1, 16 do
+ turtle.select(ii)
+ turtle.drop()
+ end
+end
+
+local function hasIdenticalItemsInStorage(storage, slot)
+ local detail = turtle.getItemDetail(slot)
+ if detail == nil then
+ return false
+ end
+
+ for _, item in pairs(storage.list()) do
+ if item.name == detail.name then
+ return true
+ end
+ end
+
+ return false
+end
+
+local function storeIdenticalItemsInStorage()
+ local storage = peripheral.wrap("front")
+ for ii = 1, 16 do
+ if hasIdenticalItemsInStorage(storage, ii) then
+ turtle.select(ii)
+ turtle.drop()
+ end
+ end
+end
+
local function getEmptySlotInStorage(storage)
return 5 -- TODO
end
@@ -28,4 +68,4 @@ local function swapSlotsInStorage(storage, slotA, slotB)
end
-return { hasItemsInStorage = hasItemsInStorage, hasItemsInTurtle = hasItemsInTurtle, swapSlotsInStorage = swapSlotsInStorage }
+return { hasItemsInStorage = hasItemsInStorage, hasItemsInTurtle = hasItemsInTurtle, fillTurtle = fillTurtle, emptyTurtle = emptyTurtle, hadIdenticalItemsInStorage = hasIdenticalItemsInStorage, storeIdenticalItemsInStorage = storeIdenticalItemsInStorage, swapSlotsInStorage = swapSlotsInStorage }