Kenanja

Turtle Mine Program

Nov 26th, 2020 (edited)
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.52 KB | None | 0 0
  1. local function checkFuel()
  2.     if turtle.getFuelLevel() < 16 then
  3.         turtle.refuel()
  4.     end
  5. end
  6.  
  7. local function moveForward(steps)
  8.     for i=1, steps do
  9.         turtle.forward()
  10.         checkFuel()
  11.         sleep(0)
  12.     end
  13. end
  14.  
  15. local function digForward()
  16.     turtle.dig()
  17.     turtle.forward()
  18.     turtle.digUp()
  19.     turtle.digDown()
  20.     checkFuel()
  21.     sleep(0)
  22. end
  23.  
  24. local function printUsages()
  25.     print("Usages:")
  26.     print("mine hollow <squareSize>")
  27.     print("mine strip <innerSquareSize> <totalSize>")
  28. end
  29.  
  30. local tArgs = { ... }
  31. if #tArgs < 1 then
  32.     printUsages()
  33.     return
  34. end
  35.  
  36. local function digInnerStripSquare(size)
  37.     for direction = 1, 4 do
  38.         for i=1,size-1 do
  39.             digForward()
  40.         end
  41.         turtle.turnRight()
  42.     end
  43.     moveForward(size-1)
  44. end
  45.  
  46. local function moveBackward(steps)
  47.     for i=1, steps do
  48.         turtle.back()
  49.         checkFuel()
  50.         sleep(0)
  51.     end
  52. end
  53.  
  54. local function digStripSquare(inner, repetitions)
  55.     for j = 1, repetitions do
  56.         for i=1, repetitions do
  57.             digInnerStripSquare(inner)
  58.         end
  59.         turtle.turnRight()
  60.         moveForward(inner - 1)
  61.         turtle.turnLeft()
  62.         moveBackward((inner -1) * repetitions)
  63.     end
  64.     turtle.turnRight()
  65.     moveBackward((inner -1) * repetitions)
  66.     turtle.turnLeft()
  67. end
  68.  
  69. local function digHollowSquare(size)
  70.     for j = 1, size do
  71.         for i=1, size-1 do
  72.             digForward()
  73.         end
  74.         if j < size then
  75.             if  j % 2 == 0 then
  76.                 turtle.turnLeft()
  77.                 digForward()
  78.                 turtle.turnLeft()
  79.             else
  80.                 turtle.turnRight()
  81.                 digForward()
  82.                 turtle.turnRight()
  83.             end
  84.             sleep(0)
  85.         end
  86.     end
  87.     if size % 2 == 0 then
  88.         turtle.turnLeft()
  89.         for i=1, size-1 do
  90.             turtle.back()
  91.             checkFuel()
  92.             sleep(0)
  93.         end
  94.         turtle.turnLeft()
  95.     else
  96.         turtle.turnRight()
  97.         for i=1, size-1 do
  98.             turtle.back()
  99.             checkFuel()
  100.             sleep(0)
  101.         end
  102.         turtle.turnLeft()
  103.         for i=1, size-1 do
  104.             turtle.back()
  105.             checkFuel()
  106.             sleep(0)
  107.         end
  108.     end
  109. end
  110.  
  111. local sCommand = tArgs[1]
  112. if sCommand == "hollow" then
  113.     digHollowSquare(tonumber(tArgs[2]))
  114. elseif sCommand == "strip" then
  115.     digStripSquare(tonumber(tArgs[2]), math.ceil(tonumber(tArgs[3])/tonumber(tArgs[2])))
  116. else
  117.     printUsages()
  118. end
  119.    
  120.    
  121.  
Add Comment
Please, Sign In to add comment