Advertisement
Guest User

mine3

a guest
Sep 2nd, 2014
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.56 KB | None | 0 0
  1. function callError(errorString)
  2.     shell.exit()
  3. end
  4.  
  5. function digUp()
  6.     while turtle.detectUp() do
  7.         turtle.digUp()
  8.     end
  9. end
  10.  
  11. function moveForward(maxTries)
  12.     for i = 0, maxTries, 1 do
  13.         if turtle.forward() then
  14.             return
  15.         end
  16.        
  17.         turtle.dig()
  18.        
  19.         sleep(1)
  20.     end
  21.    
  22.     callError("Move Forward Error")
  23. end
  24.  
  25. function moveUp(maxTries)
  26.     for i = 0, maxTries, 1 do
  27.         if turtle.up() then
  28.             return
  29.         end
  30.        
  31.         turtle.digUp()
  32.        
  33.         sleep(1)
  34.     end
  35.    
  36.     callError("Move Up Error")
  37. end
  38.  
  39. function makeATurn(turn)
  40.     if turn then
  41.         turtle.turnRight()
  42.         turtle.dig()
  43.         moveForward(10)
  44.         turtle.turnRight()
  45.     else
  46.         turtle.turnLeft()
  47.         turtle.dig()
  48.         moveForward(10)
  49.         turtle.turnLeft()
  50.     end
  51. end
  52.  
  53. function makeATurnUp()
  54.     moveUp(10)
  55.     digUp()
  56.     moveUp(10)
  57.    
  58.     turtle.turnLeft()
  59.     turtle.turnLeft()
  60. end
  61.  
  62. function mineARow(amount)
  63.     for i = 0, amount - 1, 1 do
  64.         if i < amount - 1 then
  65.             turtle.dig()
  66.             digUp()
  67.             moveForward(10)
  68.         end
  69.        
  70.         digUp()
  71.     end
  72. end
  73.  
  74. function mineLastRow(amount)
  75.     for i = 0, amount - 1, 1 do
  76.         if i < amount - 1 then
  77.             turtle.dig()
  78.             moveForward(10)
  79.         end
  80.        
  81.         digUp()
  82.     end
  83. end
  84.  
  85. function mineALayer(amount, length, turn)
  86.     for i = 0, length - 1, 1 do
  87.         mineARow(amount)
  88.        
  89.         if i < length - 1 then
  90.             makeATurn(turn)
  91.        
  92.             turn = not turn
  93.         end
  94.     end
  95.    
  96.     return turn
  97. end
  98.  
  99. function mineLastLayer(amount, length, turn)
  100.     for i = 0, length - 1, 1 do
  101.         mineLastRow(amount)
  102.  
  103.   if i < length - 1 then
  104.      makeATurn(turn)
  105.    
  106.      turn = not turn
  107.   end
  108.     end
  109. end
  110.  
  111. function mine(x, y, z)
  112.     turn = true
  113.    
  114.     turtle.dig()
  115.     moveForward(10)
  116.    
  117.     for i = 0, y - 1, 2 do
  118.         if i == y - 1 then
  119.              print(turn)
  120.     mineLastLayer(z, x, turn)
  121.         return
  122.         end
  123.        
  124.         turn = mineALayer(z, x, turn)
  125.        
  126.         makeATurnUp()
  127.     end
  128. end
  129.  
  130. function startMining()
  131.     print("This turtle is mining from the lower left to the upper right!\n")
  132.     print("X is the width\n")
  133.     print("Y is the height\n")
  134.     print("Z is the depth\n")
  135.    
  136.     print("X:")
  137.     x = tonumber(read())
  138.    
  139.     print("Y:")
  140.     y = tonumber(read())
  141.    
  142.     print("Z:")
  143.     z = tonumber(read())
  144.    
  145.     print("You entered: X = " .. x .. "Y = " .. y .. "Z = " .. z .. "\n")
  146.     print("Is that correct: Y/N")
  147.    
  148.     choice = ""
  149.    
  150.     while true do
  151.         shell.run("clear")
  152.         print(choice .. " is not a valid input! Only use Y or N\n\n")
  153.    
  154.         print("You entered: X = " .. x .. "Y = " .. y .. "Z = " .. z .. "\n")
  155.         print("Is that correct: Y/N")
  156.    
  157.         choice = read()
  158.  
  159.   if choice == "Y" or choice == "N" then
  160.     break
  161.   end
  162.     end
  163.    
  164.     if choice == "Y" then
  165.         mine(x, y, z)
  166.     end
  167. end
  168.  
  169. startMining()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement