SHOW:
|
|
- or go back to the newest paste.
1 | - | local component = require("component") |
1 | + | local component = require("component") |
2 | - | local sides = require("sides") |
2 | + | local sides = require("sides") |
3 | - | local os = require("os") |
3 | + | local os = require("os") |
4 | - | |
4 | + | |
5 | - | local in_side = sides.south |
5 | + | local in_side = sides.south |
6 | - | local out_side = sides.up |
6 | + | local out_side = sides.up |
7 | - | local sleep_t = 0.1 |
7 | + | local sleep_t = 0.1 |
8 | - | local tp = component.transposer |
8 | + | local tp = component.transposer |
9 | - | |
9 | + | |
10 | - | local function is_empty(tp, side) |
10 | + | local function is_empty(tp, side) |
11 | - | local max = tp.getInventorySize(side) |
11 | + | local max = tp.getInventorySize(side) |
12 | - | for idx = 1, max do |
12 | + | for idx = 1, max do |
13 | - | if tp.getStackInSlot(side, idx) ~= nil then return false end |
13 | + | if tp.getStackInSlot(side, idx) ~= nil then return false end |
14 | - | end |
14 | + | end |
15 | - | return true |
15 | + | return true |
16 | - | end |
16 | + | end |
17 | - | |
17 | + | |
18 | - | local function transfer_single(tp, in_, in_slot, out_, out_slot) |
18 | + | local function transfer_single(tp, in_, in_slot, out_, out_slot) |
19 | - | tp.transferItem(in_, out_, tp.getStackInSlot(in_, in_slot).count, in_slot, out_slot) |
19 | + | tp.transferItem(in_, out_, tp.getStackInSlot(in_, in_slot).count, in_slot, out_slot) |
20 | - | end |
20 | + | end |
21 | - | |
21 | + | |
22 | - | local function transfer_all(tp, in_, out_) |
22 | + | local function transfer_all(tp, in_, out_) |
23 | - | local out_slot = 1 |
23 | + | local out_slot = 1 |
24 | - | local max = tp.getInventorySize(in_) |
24 | + | local max = tp.getInventorySize(in_) |
25 | - | for idx = 1, max do |
25 | + | for idx = 1, max do |
26 | - | while tp.getStackInSlot(out_, out_slot) ~= nil do out_slot = out_slot + 1 end |
26 | + | while tp.getStackInSlot(out_, out_slot) ~= nil do out_slot = out_slot + 1 end |
27 | - | transfer_single(tp, in_, idx, out_, out_slot) |
27 | + | transfer_single(tp, in_, idx, out_, out_slot) |
28 | - | end |
28 | + | end |
29 | - | end |
29 | + | end |
30 | - | |
30 | + | |
31 | - | local function main() |
31 | + | local function main() |
32 | - | while true do |
32 | + | while true do |
33 | - | while tp.getStackInSlot(in_side, 1) == nil do os.sleep(sleep_t) end |
33 | + | while tp.getStackInSlot(in_side, 1) == nil do os.sleep(sleep_t) end |
34 | - | local prev = tp.getStackInSlot(in_side, 1) |
34 | + | local prev = tp.getStackInSlot(in_side, 1) |
35 | - | local function is_same(lstack, rstack) |
35 | + | local function is_same(lstack, rstack) |
36 | - | return lstack ~= nil and lstack.label == rstack.label and lstack.count == rstack.count |
36 | + | return lstack ~= nil and lstack.label == rstack.label and lstack.count == rstack.count |
37 | - | end |
37 | + | end |
38 | - | while is_same(tp.getStackInSlot(in_side, 1), prev) do os.sleep(sleep_t) end |
38 | + | while is_same(tp.getStackInSlot(in_side, 1), prev) do os.sleep(sleep_t) end |
39 | - | while not is_empty(tp, in_side) do transfer_all(tp, in_side, out_side) end |
39 | + | while not is_empty(tp, in_side) do transfer_all(tp, in_side, out_side) end |
40 | - | os.sleep(sleep_t) |
40 | + | os.sleep(sleep_t) |
41 | - | end |
41 | + | end |
42 | - | end |
42 | + | end |
43 | - | |
43 | + | |
44 | main() |