Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- links = {}
- function log(t) print(t) end
- function loadLink(l)
- local newLink = {}
- for i in string.gmatch(l,"[^!;]+![^!;]+;") do
- local k,v = string.match(i,"([^!]+)!([^;]+)")
- newLink[k] = v
- --[[
- {
- from, fromslot, to, toslot, limit, filter
- }
- ]]--
- end
- return newLink
- end
- for l in io.lines("/warehouse_links.list") do
- table.insert(links,loadLink(l))
- end
- function tryPush(from, to, fromslot, toslot, limit, filter)
- limit = limit or 64
- detail = peripheral.call(from,"getItemDetail",fromslot)
- if filter then
- if detail.name~=filter then
- return 0
- end
- end
- local r = peripheral.call(from,"pushItemsTo",to,fromslot,limit,toslot)
- log(("[%d x %s] (%d@%s)->(%d@%s)"):format(detail.count,detail.name,fromslot,from,toslot,to))
- return r
- end
- function handleLink(link)
- if link.fromslot==-1 then
- for i=1,peripheral.call(link.from,"size") do
- tryPush(link.from, link.to,link.fromslot, link.toslot, link.limit, link.filter)
- end
- elseif link.fromslot then
- peripheral.call(link.from,"pushItemsTo", link.to, link.fromslot, link.max or 64, link.toslot)
- else
- for i=1,peripheral.call(link.from,"size") do
- if tryPush(link.from, link.to, link.fromslot, link.toslot, link.limit, link.filter)>0 then
- return
- end
- end
- end
- end
- function handleLinks()
- for _,link in pairs(links) do
- handleLink(link)
- end
- end
- while true do
- handleLinks()
- sleep(3)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement