Advertisement
SavageCore

Untitled

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