NiallDoherty

Mine (14/07/16)

Apr 16th, 2019 (edited)
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.09 KB | None | 0 0
  1. local tArgs = {...}
  2. forward = tonumber(tArgs[1])
  3. across = tonumber(tArgs[2])
  4.  
  5. actualDown = tonumber(tArgs[3])
  6. remainder = actualDown % 3
  7. down = math.ceil(actualDown / 3)
  8.  
  9. direction = tArgs[4]
  10.  
  11. function dig()
  12.   while turtle.detect() do
  13.       turtle.dig()
  14.   end
  15. end
  16.  
  17. function digDown()
  18.   if turtle.detectDown() then
  19.     turtle.digDown()
  20.   end
  21. end
  22.  
  23. function digUp()
  24.   while turtle.detectUp() do
  25.     turtle.digUp()
  26.   end
  27. end
  28.  
  29. function move()
  30.   while not turtle.forward() do
  31.     turtle.attack()
  32.     turtle.dig()
  33.   end
  34. end
  35.  
  36. function moveDown(amount)
  37.   for i = 1, amount do
  38.     digDown()
  39.     turtle.down()
  40.   end
  41. end
  42.  
  43. function changeDirection()
  44.   if(direction == "right") then
  45.     direction = "left"
  46.   else
  47.     direction = "right"
  48.   end
  49. end
  50.  
  51. function unload()
  52.   digUp()
  53.   turtle.select(16)
  54.   turtle.placeUp()
  55.   for i = 1, 15 do
  56.     turtle.select(i)
  57.     turtle.dropUp()
  58.   end
  59.   turtle.select(16)
  60.   turtle.digUp()
  61.   turtle.select(1)
  62.   return turtle.getItemCount(15) == 0
  63. end
  64.  
  65. function checkFull()
  66.   while turtle.getItemCount(15) > 0 do
  67.     if not unload() then
  68.         print("Ender chest full!")
  69.         sleep(10)
  70.     end
  71.   end
  72. end
  73.  
  74. function mineForward(length)
  75.   for x = 1, length do
  76.     checkFull()
  77.     if x ~= length then
  78.       dig()
  79.     end
  80.     digUp()
  81.     digDown()
  82.     if x < length then      
  83.       move()
  84.     end
  85.   end
  86. end
  87.  
  88. function turn()
  89.   if(direction == "right") then
  90.     turtle.turnRight()
  91.   else
  92.     turtle.turnLeft()
  93.   end
  94. end
  95.  
  96. function nextRow()
  97.   turn()
  98.   dig()
  99.   move()
  100.   turn()
  101.   changeDirection()
  102. end
  103.  
  104. function nextLevel(last)
  105.   turn()
  106.   turn()
  107.   if not last then
  108.     moveDown(3)
  109.   else
  110.       if(remainder == 2) then
  111.         moveDown(2)
  112.       else
  113.         moveDown(1)
  114.       end
  115.   end
  116. end
  117.  
  118. function main()
  119.   for x = 1, down do
  120.     for y = 1, across do
  121.       mineForward(forward)
  122.       if y < across then
  123.         nextRow()  
  124.       end
  125.     end
  126.    
  127.    
  128.     last = (x == down-remainder)
  129.     if(x ~= down) then
  130.         nextLevel(last)
  131.     else
  132.         turtle.down()
  133.     end    
  134.   end
  135. end
  136.  
  137. main()
Add Comment
Please, Sign In to add comment