commit 37bcfea10db07b07c49ed2e41958b98b8dcbc586 Author: D4VID Date: Sun Dec 1 20:17:00 2024 +0100 Transposer testing diff --git a/storage.lua b/storage.lua new file mode 100644 index 0000000..fdd9b67 --- /dev/null +++ b/storage.lua @@ -0,0 +1,48 @@ +local component = require('component') +local event = require('event') +local serialization = require('serialization') +local sides = require('sides') + +local transposer = component.proxy(component.get("260", "transposer")) + +IN_DIR = sides.south +OUT_DIR = sides.north + +while true do + + local up = transposer.getAllStacks(IN_DIR) + local stack = up() + local slot = 1 + while stack do + if stack.name then + print(serialization.serialize(stack)) + + -- find the first empty slot + local output = transposer.getAllStacks(OUT_DIR) + local output_stack = output() + local dest_slot = 1 + while output_stack do + -- find stack that matches item + if not output_stack.name then + break + end + dest_slot = dest_slot + 1 + output_stack = output() + end + if dest_slot > transposer.getInventorySize(OUT_DIR) then + print("Bottom inventory full") + break + end + local result = transposer.transferItem(IN_DIR, OUT_DIR, stack.size, slot, dest_slot) + print(result) + -- todo handle if not everything was transfered + end + stack = up() + slot = slot + 1 + end + + -- "sleep" + if event.pull(2, "interrupted") then + break + end +end