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 thread = require("thread")
- local event = require("event")
- local shell = require("shell")
- local modem = component.modem
- local port = 666
- local sleep_t = 0.10
- local timeout_t = 1.00
- function transfer_to(tp, in_side, in_slot, out_side, out_slot)
- tp.transferItem(in_side, out_side, tp.getStackInSlot(in_side, in_slot).count, in_slot, out_slot)
- end
- function transfer_all(tp, in_side, out_side)
- 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 then tp.transferItem(in_side, out_side, in_stacks[in_slot].count, in_slot, out_slot) end
- end
- end
- function is_empty(tp, side)
- local stacks = tp.getAllStacks(side)
- for slot = 1, stacks.count() do
- if stacks[slot] ~= nil then return false end
- end
- return true
- end
- function slave_loop()
- local tp = component.transposer
- local prim_in_side = sides.west
- local prim_out_side = sides.down
- local auxl_in_side = sides.east
- local auxl_out_side = sides.south
- local output_side = sides.north
- modem.open(port)
- modem.setStrength(512)
- while true do
- function wait_for_crafting_request(event_name, ...)
- if event_name == "modem_message" then
- local message = select(5, ...)
- if message == "reply_if_available" then return true end
- end
- return false
- end
- local master_addr, port = select(1 + 2, event.pullFiltered(wait_for_crafting_request))
- modem.send(master_addr, port, "altar_available")
- function wait_for_master_response(event_name, ...)
- if event_name == "modem_message" then
- local message = select(5, ...)
- if message == "proceed" or message == "cease" then return true end
- end
- return false
- end
- local message = select(1 + 5, event.pullFiltered(wait_for_master_response))
- if message == "proceed" then
- modem.send(master_addr, port, "proceed_ack")
- transfer_all(tp, auxl_in_side, auxl_out_side)
- while not is_empty(tp, auxl_out_side) do os.sleep(sleep_t) end
- local orig = tp.getStackInSlot(prim_in_side, 1)
- transfer_to(tp, prim_in_side, 1, prim_out_side, 1)
- modem.send(master_addr, port, "buffers_freed")
- local function is_same(stack, cmp)
- return stack ~= nil and stack.label == cmp.label and stack.count == cmp.count
- end
- while is_same(tp.getStackInSlot(prim_out_side, 1), orig) do os.sleep(sleep_t) end
- transfer_to(tp, prim_out_side, 1, output_side, 1)
- while not is_empty(tp, output_side) do os.sleep(sleep_t) end
- end
- end
- end
- slave_loop()
Add Comment
Please, Sign In to add comment