Advertisement
SavageCore

branch

Apr 23rd, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.54 KB | None | 0 0
  1. shell.run("clear")
  2. local torch = turtle.getItemCount(1)
  3. local chests = turtle.getItemCount(2)
  4. local fuel = turtle.getFuelLevel()
  5. local dist = 0
  6. local retdist = 0
  7. local t = 0
  8. local name = os.getComputerLabel()
  9.  
  10. function start()
  11.   print ""
  12.     print "Welcome to the autominer3000"
  13.     print ""
  14.   print "Please have torches in slot 1, chests in 2 and fuel in 3 upon startup."
  15.   print ""
  16.   print "Failure to do so may have unforeseen health risks."
  17.   print ""
  18.   text = "[" .. name .. "~] How deep do you want each branch? (Length) (1/99): "
  19.     io.write(text)
  20.     ll = io.read()
  21.   if not tonumber(ll) then
  22.     print ""
  23.         print "Please enter a valid number"
  24.         print ""
  25.     start()
  26.   else
  27.     length = ll+1
  28.     start_1()
  29.   end
  30.   if tonumber(length) < 1 then
  31.         print ""
  32.         print "Number must be positive"
  33.         print ""
  34.         start()
  35.     end
  36. end
  37.  
  38. function start_1()  
  39.   text = "[" .. name .. "~] How many branches do you want? (Width) (1/99): "
  40.     io.write(text)
  41.     w = io.read()
  42.   if not tonumber(w) then
  43.     print ""
  44.         print "Please enter a valid number"
  45.         print ""
  46.     start_1()
  47.   else
  48.     width = w+1
  49.     start_2()
  50.   end
  51.   if tonumber(w) < 1 then
  52.         print ""
  53.         print "Number must be positive"
  54.         print ""
  55.         start_1()
  56.     end
  57. end
  58.  
  59. function start_2()  
  60.   text = "[" .. name .. "~] Enderchest? (y/n): "
  61.     io.write(text)
  62.     e = io.read()
  63.   if e == "y" then
  64.     enderchest = true
  65.     start_3()
  66.   elseif e == "n" then
  67.     enderchest = false
  68.     start_3()
  69.   else
  70.     print ""
  71.     print "Please enter y or n"
  72.     print ""
  73.     start_2()
  74.   end
  75. end
  76.  
  77. function start_3()  
  78.   text = "[" .. name .. "~] Direction (left/right): "
  79.     io.write(text)
  80.     d = io.read()
  81.   if d == "left" then
  82.     direction = d
  83.     start_4()
  84.   elseif d == "right" then
  85.     direction = d
  86.     start_4()
  87.   else
  88.     print ""
  89.     print "Please enter y or n"
  90.     print ""
  91.     start_3()
  92.   end
  93. end
  94.  
  95. function start_4()
  96.   print ("")
  97.   print ("I will dig ".. w .. ", " .. ll .. " long tunnel(s)")
  98.   print ("")
  99.   if enderchest == true then
  100.     print("Enderchest: Yes")
  101.   else
  102.     print("Enderchest: No")
  103.   end
  104.   print ("")
  105.   print ("Making branches to the " .. direction)
  106.   print ("")
  107.   text = "[" .. name .. "~] Are you sure you want to procede? (y/n): "
  108.     io.write(text)
  109.     c = io.read()
  110.   if c == "y" then
  111.     --if check_items() then run() end
  112.     run()
  113.   elseif c == "n" then
  114.     print "Be seeing you!"
  115.   else
  116.     print ""
  117.     print "Please enter y or n"
  118.     print ""
  119.     start_4()
  120.   end
  121. end
  122.  
  123. function check_items()
  124.  
  125. end
  126.  
  127. function reFuel()
  128.     for i = 3, 16 do
  129.       turtle.select(i)
  130.       turtle.refuel(1)
  131.       if turtle.getFuelLevel() > 0 then
  132.         turtle.select(1)
  133.         local fuel = turtle.getFuelLevel()
  134.         break
  135.       end
  136.     end
  137.     addFuel()
  138. end
  139.  
  140. function addFuel()
  141.     print ""
  142.     print "Add fuel to continue..."
  143.     turtle.select(3)
  144.     while turtle.getFuelLevel() == 0 do
  145.         turtle.refuel(1)
  146.         sleep(1)
  147.     end
  148.     print ""
  149.     print "Yummy, thank you!"
  150.     print ""
  151.     local fuel = turtle.getFuelLevel()
  152.   run()
  153. end
  154.  
  155. function forward()
  156.   if turtle.getFuelLevel() < 1 then
  157.     reFuel()
  158.   end
  159.   if turtle.detect() then turtle.dig() end
  160.   turtle.forward()
  161.   if turtle.forward() then dist = dist + 1 end
  162.   dump()
  163.   turtle.digUp()
  164. end
  165.  
  166. function turn()
  167.   if lastDirection == "right" then direction = "left" end
  168.   if lastDirection == "left" then direction = "right" end
  169.   if direction == "left" then
  170.     turtle.turnLeft()
  171.     forward()
  172.     forward()
  173.     forward()
  174.     forward()
  175.     turtle.turnLeft()
  176.     lastDirection = "left"
  177.     dist = 0
  178.   elseif direction == "right" then
  179.     turtle.turnRight()
  180.     forward()
  181.     forward()
  182.     forward()
  183.     forward()
  184.     turtle.turnRight()
  185.     lastDirection = "right"
  186.     dist = 0
  187.   end
  188. end
  189.  
  190. function dump()
  191.   if turtle.getItemCount(16)>0 then
  192.     turtle.digDown()
  193.     turtle.select(2)
  194.     turtle.placeDown()
  195.     turtle.select(1)
  196.     for slot = 4,16,1 do
  197.       turtle.select(slot)
  198.       turtle.dropDown()
  199.     end
  200.     turtle.select(1)
  201.     if enderchest then
  202.       turtle.select(2)
  203.       turtle.digDown()
  204.     else
  205.       chests = chests - 1  
  206.     end
  207.   end
  208. end
  209.  
  210. function light()
  211.   turtle.turnLeft()
  212.   turtle.turnLeft()
  213.   turtle.select(1)
  214.   turtle.place()
  215.   turtle.turnLeft()
  216.   turtle.turnLeft()
  217.   torch = torch - 1
  218. end
  219.  
  220. function run()
  221.   if fuel < 1 then reFuel() end
  222.   while dist < tonumber(length) do
  223.     t = t + 1
  224.     if t == 12 then
  225.       light()
  226.       t = 0
  227.     end
  228.     forward()
  229.     retdist = dist + 14
  230.     local fuel = turtle.getFuelLevel()
  231.   end
  232.   turn()
  233.   run()
  234. end
  235.  
  236. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement