Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Bean Counter
- -- How much stuff are we getting?
- -- By Fenthis
- -- Peripheral Sides
- local pdirs = { "top", "bottom", "front", "back", "left", "right" }
- -- Map out the other side from the inventory we find
- local oposit = { [0] = 1, 0, 3, 2, 5, 4 }
- -- Direction names
- local sdirs = { [0] = "top", "bottom", "north", "south", "west", "east" }
- -- Sleep between cycles
- local delay = 1
- -- Status channel
- local status_channel = 21231
- local sorter
- local modem
- local i
- for i = 1, #pdirs do
- sorter = peripheral.wrap(pdirs[i])
- if p then
- if p.sort then
- sorter = p
- end
- if p.transmit then
- modem = p
- end
- end
- end
- if not sorter then
- error("Can not find the interactive sorter!")
- end
- if not modem then
- print("WARNING: No modem found, unable to broadcast updates.")
- end
- local inventories = {}
- for i = 0, 5 do
- if sorter.list(i) then
- table.insert(inventories, { ["direction"] = i, ["lastlist"] = {} })
- print("Inventory to the "..sdirs[i])
- end
- end
- if #inventories == 0 then
- error("Cound not find any attached inventories.")
- end
- -- Only update when actually moving stuff
- local seen = {}
- -- New inventory we are working with
- local new
- print("Running! Hold CTRL-T to quit.")
- while true do
- local dirty = false
- for i = 1, #inventories do
- new = sorter.list(inventories[i].direction)
- for item, count in pairs(new) do
- if new[item] > 64 or new[item] == inventories[i].lastlist[item] then
- sorter.extract(
- inventories[i].direction,
- item,
- oposit[inventories[i].direction],
- new[item]
- )
- print("Extracting: ", item, " count ", new[item],
- " fromt ", inventories[i].direction,
- " to ", oposit[inventories[i].direction])
- if not seen[item] then
- seen[item] = 0
- end
- seen[item] = seen[item] + new[item]
- new[item] = nil
- dirty = true
- end
- end
- inventories[i].lastlist = new
- end
- if dirty then
- modem.transmit(status_channel, 0, textutils.serialize(seen))
- end
- sleep(delay)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement