Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- delay=5
- ap=peripheral.wrap'left'
- size=108
- function getItems()
- local t={}
- for i=1,size do
- local s,n=ap.getItem(i-1)
- if s then
- t[s]=t[s] or {n=0,i={}}
- t[s].i[i]=n
- t[s].n=t[s].n+n
- end
- end
- return t
- end
- function pullItem(t,n)
- local t_t={}
- local p=0
- for i=table.maxn(t.i),(next(t.i) or math.huge),-1 do
- if t.i[i] then
- local taken=math.min(n-p,t.i[i])
- t_t[i]=taken
- t.i[i]=t.i[i]-taken
- if t.i[i]==0 then t.i[i]=nil end
- t.n=t.n-taken
- p=p+taken
- if p>=n then
- break
- end
- end
- end
- for i,n in pairs(t_t) do
- ap.suck(i-1,n)
- end
- end
- local slots={1,2,5,6}
- function work()
- local worked=false
- local t=getItems()
- for s,tt in pairs(t) do
- local n=tt.n
- n=n-(n%4)
- local r=n%4
- local q=(n-r)/4
- if q>0 then
- local left=q
- repeat
- local n=math.min(64,left)
- for _,i in pairs(slots) do
- turtle.select(i)
- pullItem(tt,n)
- end
- if not turtle.craft(n) then clear(turtle.dropUp,{1,2,3,5,6,7,9,10,11})
- else worked=true end
- turtle.dropUp()
- left=left-64
- until left<0
- end
- end
- return worked
- end
- function clear(drop,_slots)
- _slots=_slots or slots
- for _,i in pairs(_slots) do
- turtle.select(i)
- drop()
- end
- end
- clear(turtle.dropUp)
- repeat
- while work() do
- end
- sleep(delay)
- until false
- ap.getItem()
Advertisement
Add Comment
Please, Sign In to add comment