Advertisement
SavageCore

Untitled

Apr 23rd, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.01 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.   if torch < 2 then
  20.     addTorches()
  21.   end
  22.   if chests < 2 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.     print ""
  166.     print "Add [2] chests to slot [2] continue..."
  167.   print ""
  168.     turtle.select(2)
  169.   while turtle.getItemCount(2) < 2 do
  170.     sleep(1)
  171.   end
  172.   local chests = turtle.getItemCount(2)
  173.     print ""
  174.     print "Store all the things!"
  175.     print ""
  176. end
  177.  
  178. function addTorches()
  179.     print ""
  180.     print "Add [2] torches to slot [1] to continue..."
  181.   print ""
  182.     turtle.select(1)
  183.   while turtle.getItemCount(1) < 2 do
  184.     sleep(1)
  185.   end
  186.   local torch = turtle.getItemCount(1)
  187.     print ""
  188.     print "LET THERE BE LIGHT!"
  189.     print ""
  190. end
  191.  
  192. function forward()
  193.   if turtle.getFuelLevel() < 1 then
  194.     reFuel()
  195.   end
  196.   if turtle.detect() then
  197.     turtle.dig()
  198.     sleep(.6)
  199.         while turtle.detectUp() == true do
  200.             turtle.digUp()
  201.             sleep(.6)
  202.         end
  203.   end
  204.   if turtle.forward() then
  205.    dist = dist + 1
  206.   end
  207.   dump()
  208.   turtle.digUp()
  209. end
  210.  
  211. function turn()
  212.   if lastDirection == "right" then direction = "left" end
  213.   if lastDirection == "left" then direction = "right" end
  214.   if direction == "left" then
  215.     turtle.turnLeft()
  216.     forward()
  217.     turtle.turnRight()
  218.     turtle.turnRight()    
  219.     turtle.select(1)
  220.     turtle.place()
  221.     turtle.turnRight()
  222.     turtle.turnRight()
  223.     forward()
  224.     forward()
  225.     forward()
  226.     turtle.turnLeft()
  227.     lastDirection = "left"
  228.     dist = 0
  229.     branches = branches+1
  230.   elseif direction == "right" then
  231.     turtle.turnRight()
  232.     forward()
  233.     turtle.turnLeft()
  234.     turtle.turnLeft()    
  235.     turtle.select(1)
  236.     turtle.place()
  237.     turtle.turnLeft()
  238.     turtle.turnLeft()
  239.     forward()
  240.     forward()
  241.     forward()
  242.     turtle.turnRight()
  243.     lastDirection = "right"
  244.     dist = 0
  245.     branches = branches+1
  246.   end
  247. end
  248.  
  249. function dump()
  250.   if turtle.getItemCount(16)>0 then
  251.     turtle.digDown()
  252.     turtle.select(2)
  253.     turtle.placeDown()
  254.     turtle.select(1)
  255.     for slot = 4,16,1 do
  256.       turtle.select(slot)
  257.       turtle.dropDown()
  258.     end
  259.     turtle.select(1)
  260.     if enderchest then
  261.       turtle.select(2)
  262.       turtle.digDown()
  263.     else
  264.       chests = chests - 1
  265.       if chests == 1 then addChests() end
  266.     end
  267.   end
  268. end
  269.  
  270. function light()
  271.   turtle.turnLeft()
  272.   turtle.turnLeft()
  273.   turtle.select(1)
  274.   turtle.place()
  275.   turtle.turnLeft()
  276.   turtle.turnLeft()
  277.   torch = torch - 1
  278.   if torch == 1 then addTorches() end
  279.   t = 0
  280. end
  281.  
  282. function run()
  283.   print("dist:" .. dist)
  284.   print("length:" .. length)
  285.   print("branches:" .. branches)
  286.   print("torches:" .. torch)
  287.   print("chests:" .. chests)
  288.   if torch < 2 then
  289.     addTorches()
  290.   end
  291.   if chests < 2 then
  292.     addChests()
  293.   end  
  294.   while dist < tonumber(length) and branches <= tonumber(width) do
  295.     t = t + 1
  296.     if t == 12 then
  297.       light()
  298.     end
  299.     forward()
  300.     retdist = dist + 14
  301.     local fuel = turtle.getFuelLevel()
  302.   end
  303.   if branches == tonumber(width) and dist == tonumber(length) then os.shutdown() end
  304.   turn()
  305.   run()
  306. end
  307.  
  308. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement