Advertisement
SavageCore

Untitled

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