Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- load libraries
- os.loadAPI("dataLib")
- local pretty = require "cc.pretty"
- -- peripheral setup
- local import = peripheral.wrap("right")
- local export = peripheral.wrap("left")
- local modem = peripheral.wrap("top")
- modem.open(1)
- -- variables setup
- local items = {}
- function stripModName(itemname)
- local parts= {}
- for part in itemname:gmatch("[^:]+") do
- parts[ #parts + 1 ] = part
- end
- return parts[2]
- end
- function stripEssence(itemname)
- return itemname:gsub("_essence", "")
- end
- function addItem(item)
- local name = stripModName(item.name)
- name = stripEssence(name)
- if items[name] then
- items[name] = items[name] + item.count
- else
- items[name] = item.count
- end
- end
- function waitForRequest()
- parallel.waitForAny(wait,getRequest)
- end
- function wait()
- sleep(0.5)
- end
- function getRequest()
- local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
- if message == "provideEssenceCount" then
- modem.transmit(2,1,items)
- end
- end
- while true do
- for i=1,27 do
- local item = import.getItemDetail(i)
- if item then
- addItem(item)
- import.pushItems("left", i, item.count)
- end
- end
- write(os.time() .. ": ")
- waitForRequest()
- pretty.pretty_print(items)
- end
Advertisement
Advertisement
Advertisement
RAW Paste Data
Copied
Advertisement