skypop

PaperCraft

Sep 16th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.19 KB | None | 0 0
  1. local i
  2. local function suck()
  3.     for i=1,4 do
  4.         turtle.suck()
  5.         if i<8 then turtle.turnLeft() end
  6.     end
  7. end
  8.  
  9. local item
  10. local function dump(startSlot,endSlot)
  11.     startSlot = startSlot or 1
  12.     endSlot = endSlot or 16
  13.     for i=startSlot,endSlot do
  14.         item = turtle.getItemDetail(i)
  15.         if item then
  16.             turtle.select(i)
  17.             if item.name=="minecraft:reeds" then
  18.                 turtle.dropUp(64)
  19.             elseif item.name=="minecraft:paper" then
  20.                 turtle.dropDown(64)
  21.             else
  22.                 turtle.drop(64)
  23.             end
  24.         end
  25.     end
  26. end
  27.  
  28. local count
  29. local _f = math.floor
  30. local function prepare()
  31.     count = 0
  32.     for i=1,16 do
  33.         item = turtle.getItemDetail(i)
  34.         if item then
  35.             if item.name=="minecraft:reeds" then
  36.                 count = count + turtle.getItemCount(i)
  37.             elseif item.name=="minecraft:paper" then
  38.                 turtle.select(i)
  39.                 turtle.dropDown(64)
  40.             else
  41.                 turtle.select(i)
  42.                 turtle.drop(64)
  43.             end
  44.         end
  45.     end
  46.     if count > 2 then
  47.         local par3 = math.min(64,_f(count/3))
  48.         for i=1,16 do
  49.             count = turtle.getItemCount(i)
  50.             if count>0 then
  51.                 if i<=3 then
  52.                     if count>par3 then
  53.                         turtle.select(i)
  54.                         turtle.transferTo(i+1,count-par3)
  55.                         turtle.dropUp(turtle.getItemCount(i)-par3)
  56.                     end
  57.                 else
  58.                     turtle.select(i)
  59.                     local slot=1
  60.                     repeat
  61.                         turtle.transferTo(slot,math.max(0,par3-turtle.getItemCount(slot)))
  62.                         slot = slot+1
  63.                     until turtle.getItemCount(i)==0 or slot>3
  64.                     turtle.dropUp(64)
  65.                 end
  66.             end
  67.         end
  68.     end
  69. end
  70.  
  71. local function validPattern()
  72.     dump(4,16)
  73.     turtle.select(1)
  74.     item = turtle.getItemDetail(1)
  75.     if item and item.name=="minecraft:reeds"
  76.     and turtle.compareTo(2)
  77.     and turtle.compareTo(3)
  78.     then
  79.         local minQty = math.min(turtle.getItemCount(1),turtle.getItemCount(2),turtle.getItemCount(3))
  80.         for i=1,3 do
  81.             if valid and turtle.getItemCount(i)>minQty then
  82.                 turtle.select(i)
  83.                 turtle.dropUp(turtle.getItemCount(i)-minQty)
  84.             end
  85.         end
  86.         return true
  87.     end
  88.     dump(1,3)
  89.     return false
  90. end
  91.  
  92. local function craft()
  93.     while validPattern() do
  94.         turtle.craft(64)
  95.     end
  96. end
  97.  
  98. local function strTime(sec)
  99.     local str,d,h,m,s = "",_f(sec/86400),_f(sec/3600)%24,_f(sec/60)%60,_f(sec%60)
  100.     if d>0 then str = d>1 and d.." days " or "1 day " end
  101.     if h>0 then str = str..h.."h" end
  102.     if m>0 then str = str..(m>9 and m or "0"..m) end
  103.     if h==0 then str = m>0 and str..":"..(s>9 and s or "0"..s) or s.."s" end
  104.     return str
  105. end
  106. local w,h = term.getSize()
  107. local function computer()
  108.     term.setBackgroundColor(colors.white)
  109.     term.setTextColor(colors.black)
  110.     term.setCursorPos(1,1) term.clearLine()
  111.     term.write("#"..os.getComputerID().." - "..os.getComputerLabel())
  112.     term.setCursorPos(1,2) term.clearLine()
  113.     term.write("Running: "..strTime(os.clock()))
  114.     term.setBackgroundColor(colors.black)
  115.     term.setTextColour(colors.gray)
  116.     term.setCursorPos(1,3) term.clearLine()
  117.     term.write(string.rep(string.char(131),w))
  118.     term.setTextColor(colors.white)
  119. end
  120.  
  121. term.clear()
  122. computer()
  123. local t,e,p = os.startTimer(.1)
  124. while true do
  125.     e = os.pullEvent()
  126.     computer()
  127.     if e=="redstone" and rs.getInput("top")==false then
  128.         os.cancelTimer(t)
  129.         suck()
  130.         prepare()
  131.         craft()
  132.         dump(1,16)
  133.         t = os.startTimer(1)
  134.     elseif e=="timer" then
  135.         computer()
  136.         t = os.startTimer(1)
  137.     end
  138. end
Add Comment
Please, Sign In to add comment