Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local i
- local function suck()
- for i=1,4 do
- turtle.suck()
- if i<8 then turtle.turnLeft() end
- end
- end
- local item
- local function dump(startSlot,endSlot)
- startSlot = startSlot or 1
- endSlot = endSlot or 16
- for i=startSlot,endSlot do
- item = turtle.getItemDetail(i)
- if item then
- turtle.select(i)
- if item.name=="minecraft:reeds" then
- turtle.dropUp(64)
- elseif item.name=="minecraft:paper" then
- turtle.dropDown(64)
- else
- turtle.drop(64)
- end
- end
- end
- end
- local count
- local _f = math.floor
- local function prepare()
- count = 0
- for i=1,16 do
- item = turtle.getItemDetail(i)
- if item then
- if item.name=="minecraft:reeds" then
- count = count + turtle.getItemCount(i)
- elseif item.name=="minecraft:paper" then
- turtle.select(i)
- turtle.dropDown(64)
- else
- turtle.select(i)
- turtle.drop(64)
- end
- end
- end
- if count > 2 then
- local par3 = math.min(64,_f(count/3))
- for i=1,16 do
- count = turtle.getItemCount(i)
- if count>0 then
- if i<=3 then
- if count>par3 then
- turtle.select(i)
- turtle.transferTo(i+1,count-par3)
- turtle.dropUp(turtle.getItemCount(i)-par3)
- end
- else
- turtle.select(i)
- local slot=1
- repeat
- turtle.transferTo(slot,math.max(0,par3-turtle.getItemCount(slot)))
- slot = slot+1
- until turtle.getItemCount(i)==0 or slot>3
- turtle.dropUp(64)
- end
- end
- end
- end
- end
- local function validPattern()
- dump(4,16)
- turtle.select(1)
- item = turtle.getItemDetail(1)
- if item and item.name=="minecraft:reeds"
- and turtle.compareTo(2)
- and turtle.compareTo(3)
- then
- local minQty = math.min(turtle.getItemCount(1),turtle.getItemCount(2),turtle.getItemCount(3))
- for i=1,3 do
- if valid and turtle.getItemCount(i)>minQty then
- turtle.select(i)
- turtle.dropUp(turtle.getItemCount(i)-minQty)
- end
- end
- return true
- end
- dump(1,3)
- return false
- end
- local function craft()
- while validPattern() do
- turtle.craft(64)
- end
- end
- local function strTime(sec)
- local str,d,h,m,s = "",_f(sec/86400),_f(sec/3600)%24,_f(sec/60)%60,_f(sec%60)
- if d>0 then str = d>1 and d.." days " or "1 day " end
- if h>0 then str = str..h.."h" end
- if m>0 then str = str..(m>9 and m or "0"..m) end
- if h==0 then str = m>0 and str..":"..(s>9 and s or "0"..s) or s.."s" end
- return str
- end
- local w,h = term.getSize()
- local function computer()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(1,1) term.clearLine()
- term.write("#"..os.getComputerID().." - "..os.getComputerLabel())
- term.setCursorPos(1,2) term.clearLine()
- term.write("Running: "..strTime(os.clock()))
- term.setBackgroundColor(colors.black)
- term.setTextColour(colors.gray)
- term.setCursorPos(1,3) term.clearLine()
- term.write(string.rep(string.char(131),w))
- term.setTextColor(colors.white)
- end
- term.clear()
- computer()
- local t,e,p = os.startTimer(.1)
- while true do
- e = os.pullEvent()
- computer()
- if e=="redstone" and rs.getInput("top")==false then
- os.cancelTimer(t)
- suck()
- prepare()
- craft()
- dump(1,16)
- t = os.startTimer(1)
- elseif e=="timer" then
- computer()
- t = os.startTimer(1)
- end
- end
Add Comment
Please, Sign In to add comment