Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local sides = require("sides")
- local os = require("os")
- local tp_utils = {}
- function tp_utils.first_of(stacks, pred)
- for slot = 1, stacks.count() do
- if pred(slot, stacks[slot]) then return slot, stacks[slot] end
- end
- return -1, nil
- end
- function tp_utils.all(stacks, pred)
- local ret = {}
- for slot = 1, stacks.count() do
- if pred(slot, stacks[slot]) then table.insert(ret, table.pack(slot, stacks[slot])) end
- end
- return ret
- end
- function tp_utils.is_any(stacks, pred)
- return select(2, tp_utils.first_of(stacks, pred)) ~= nil
- end
- function tp_utils.are_all(stacks, pred)
- return not tp_utils.is_any(stacks, function(slot, stack) return not pred(slot, stack) end)
- end
- function tp_utils.is_empty(stacks)
- return tp_utils.are_all(stacks, function(slot, stack) return stack == nil end)
- end
- function tp_utils.wait_for_empty_slot(tp, side)
- local slot = -1
- while slot == -1 do
- slot, _ = tp_utils.first_of(tp.getAllStacks(side), function(slot, stack) return stack == nil end)
- os.sleep(sleep_t)
- end
- return slot
- end
- function tp_utils.transfer_all(tp, in_side, out_side, pred)
- local in_stacks = tp.getAllStacks(in_side)
- local out_slot = 1
- for in_slot = 1, in_stacks.count() do
- while tp.getStackInSlot(out_side, out_slot) ~= nil do out_slot = out_slot + 1 end
- if in_stacks[in_slot] ~= nil and pred(in_slot, in_stacks[in_slot]) then tp.transferItem(in_side, out_side, in_stacks[in_slot].count, in_slot, out_slot) end
- end
- end
- local function main()
- local tps = {}
- for addr, type in component.list() do
- if type == "transposer" then
- local tp = component.proxy(addr)
- local sys_in, drop = if tp.getInventorySize(sides.north) > tp.getInventorySize(sides.south) then sides.north, sides.south else sides.south, sides.north end
- table.insert(tps, { tp = tp, sys_in = sys_in, drop = drop, sys_out = sides.west, vacuum = sides.east, is_brewing = false, sys_in_size = tp.getInventorySize(sides.north)})
- end
- end
- while true do
- for _, stand in pairs(tps) do
- if not stand.is_brewing and stand.tp.getStackInSlot(stand.sys_in, 1) ~= nil then
- for slot = 1, stand.sys_in_size do
- if stand.tp.getStackInSlot(stand.sys_in, slot) ~= nil then
- stand.tp.transferItem(stand.sys_in, stand.drop, stand.tp.getStackInSlot(stand.sys_in, slot).count, slot, 1)
- while stand.tp.getStackInSlot(stand.drop, 1) ~= nil do os.sleep(0.1) end
- end
- end
- stand.is_brewing = true
- elseif stand.tp.getStackInSlot(stand.vacuum, 1) ~= nil then
- tp_utils.transfer_all(stand.tp, stand.vacuum, stand.sys_out, function(slot, stack) return true end)
- end
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement