Advertisement
incinirate

furnace

Jun 5th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.52 KB | None | 0 0
  1. furnaces=6
  2. --CHANGE THIS NUMBER TO THE NUMBER OF FURNACES YOU HAVE SETUP
  3. -------------------
  4. rf=furnaces
  5. af={}
  6. for i=1,rf do
  7.   af[i]=true
  8. end
  9. orders={}
  10. pf={}
  11. for i=1,rf do
  12.   pf[i]=0
  13. end
  14.  
  15. function ref()
  16.   if turtle.getFuelLevel()<1 then
  17.       slot = turtle.getSelectedSlot()
  18.       turtle.select(1)
  19.       turtle.refuel(1)
  20.       turtle.select(slot)
  21.   end
  22. end
  23.  
  24. function fd()
  25.   if not turtle.forward() then
  26.     ref()
  27.   end
  28. end
  29.  
  30. function bk()
  31.   if not turtle.back() then
  32.     ref()
  33.   end
  34. end
  35.  
  36. function up()
  37.   if not turtle.up() then
  38.     ref()
  39.   end
  40. end
  41.  
  42. function dn()
  43.   if not turtle.down() then
  44.     ref()
  45.   end
  46. end
  47.  
  48. function start()
  49.   shell.run("clear")
  50.   write("Welcome to the ")
  51.   term.setTextColor(colors.red)
  52.   print("FORGE")
  53.   term.setTextColor(colors.white)
  54.   print("Options:")
  55.   print("1: Add an order ("..rf.." furances ready)")
  56.   print("2: Check on an order")
  57.   print("3: Quit")
  58. end
  59.  
  60. function ta() turtle.turnLeft();turtle.turnLeft() end
  61.  
  62. function drop()
  63.   up()
  64.   fd()
  65.   turtle.dropDown()
  66.   bk()
  67.   dn()
  68. end
  69.  
  70. function get()
  71.   dn()
  72.   fd()
  73.   turtle.suckUp()
  74.   bk()
  75.   up()
  76. end
  77.  
  78. function nz(num)
  79.   if num<0 then
  80.     return 1
  81.   end
  82.   return num
  83. end
  84.  
  85. function chkstart()
  86.   ta()
  87.   fd()
  88.   dn()
  89.   turtle.turnLeft()
  90.   fd()
  91.   turtle.turnRight()
  92.   turtle.select(2)
  93.   turtle.suckUp()
  94.   for i=1,furnaces-1 do
  95.     fd()
  96.     turtle.suckUp()
  97.   end
  98.   turtle.turnRight()
  99.   fd()
  100.   up()
  101.   up()
  102.   bk()
  103.   turtle.turnRight()
  104.   turtle.select(9)
  105.   turtle.suckDown()
  106.   for i=1,furnaces-1 do
  107.     fd()
  108.     turtle.suckDown()
  109.   end
  110.   turtle.turnLeft()
  111.   fd()
  112.   dn()
  113.   turtle.turnRight()
  114.   fd()  
  115. end
  116.  
  117. chkstart()
  118.  
  119. while true do
  120.   start()
  121.   e,ch = os.pullEvent()
  122.   if e=="char" then
  123.     ch=tonumber(ch)
  124.     shell.run("clear")
  125.     if ch==3 then break
  126.     elseif ch==1 then
  127.       local anil=false
  128.       local anum=0
  129.       for i=1,furnaces do
  130.         if af[i] then anil=true end
  131.       end
  132.       if not anil then
  133.         print("No open furnaces ATM, check back later")
  134.         read()
  135.       else
  136.       num=0
  137.       for i=2,16 do
  138.         num=num+turtle.getItemCount(i)
  139.       end
  140.       if num==0 then
  141.         print("You need to add an item first")
  142.         read()
  143.       else
  144.         local slots = {}
  145.         for i=2,16 do
  146.           if turtle.getItemCount(i)>0 then table.insert(slots,i) end
  147.         end
  148.         if #slots>1 then
  149.           repeat
  150.             repeat
  151.               shell.run("clear")
  152.               print("More than one item detected, which slot?")
  153.               print("|**|2 |3 |4 |")
  154.               print("|5 |6 |7 |8 |")
  155.               print("|9 |10|11|12|")
  156.               print("|13|14|15|16|")
  157.               a=tonumber(read())
  158.             until tonumber(a)~=nil and a>1 and a<17
  159.           until turtle.getItemCount(a)>0
  160.         else a=slots[1] end
  161.         print("AOK")
  162.         i=0
  163.         repeat i=i+1
  164.         until af[i] or i>#af
  165.         ta()
  166.         j=0
  167.         repeat fd();j=j+1
  168.         until j==i
  169.         turtle.turnLeft()
  170.         --DROP CODE
  171.         turtle.select(a)
  172.         pf[i]=turtle.getItemCount(a)
  173.         drop()
  174.         orders[i]=os.clock()
  175.         af[i]=false
  176.         rf=rf-1
  177.         --END DROP CODE
  178.         turtle.turnLeft()
  179.         j=0
  180.         repeat fd();j=j+1
  181.         until j==i
  182.       end end
  183.     elseif ch==2 then
  184.       local anil=false
  185.       for i=1,furnaces do
  186.         if orders[i]~=nil then anil=true end
  187.       end
  188.       if anil then
  189.         repeat
  190.           shell.run("clear")
  191.           print("Which order:")
  192.           for i=1,furnaces do
  193.             if orders[i]~=nil then
  194.               print(i..": "..pf[i].." items, started "..os.clock()-orders[i].." seconds ago")
  195.             end
  196.           end
  197.           chk = tonumber(read())
  198.         until chk~=nil and chk<furnaces+1
  199.         shell.run("clear")
  200.         print("Order "..chk)
  201.         if orders[chk]==nil then
  202.           print("Has not started yet.")
  203.         else
  204.           --  |===>      |
  205.           percent=math.floor(((os.clock()-orders[chk])/(pf[chk]*10)*10))
  206.           if percent < 10 then
  207.             print("|"..string.rep("=",nz(percent))..">"..string.rep(" ",10-nz(percent)).."|")
  208.             print(percent*(10).."% Done")
  209.           else
  210.             print("Is done")
  211.           end
  212.         end
  213.         read()
  214.       else
  215.         print("No running orders.")
  216.         read()
  217.       end
  218.     end
  219.   elseif e=="timer" then
  220.     for i=1,furnaces do
  221.       if orders[i]~=nil then
  222.         if os.clock()-orders[i] >= pf[i]*10 then --Retrieve cooked items
  223.           ta()
  224.           j=0
  225.           repeat fd();j=j+1
  226.           until j==i
  227.           turtle.turnLeft()
  228.           get()
  229.           turtle.turnLeft()
  230.           j=0
  231.           repeat fd();j=j+1
  232.           until j==i
  233.           orders[i]=nil
  234.           pf[i]=0
  235.           af[i]=true
  236.           rf=rf+1
  237.         end
  238.       end
  239.     end
  240.   end
  241.   os.startTimer(1)
  242. end
  243. shell.run("clear")
  244. print("Thanks for using FORGE")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement