cacacraft

Turtle Flatten

Nov 29th, 2020 (edited)
556
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local tArgs = {...}
  2.  
  3. if #tArgs == 0 then
  4.   print("Usage: flat [length] [width] [flags]")
  5.   return
  6. else
  7.   length = tonumber(tArgs[1])
  8.   width = tonumber(tArgs[2])
  9. end
  10.  
  11. local turnFlag
  12.  
  13. if tArgs[3] == "right" then
  14.   turnFlag = true
  15. elseif tArgs[3] == "left" then
  16.   turnFlag = false
  17. end
  18.  
  19. -- Functions
  20.  
  21. local function tFuel(amount) -- By Guude
  22.   if turtle.getFuelLevel() < 5 then
  23.     turtle.select(16)
  24.     turtle.refuel(amount)
  25.     turtle.select(1)
  26.   end
  27. end
  28.  
  29. local function digMove()
  30.   if turtle.detect() then
  31.     repeat
  32.       turtle.dig()
  33.       sleep(.25)
  34.     until turtle.detect() == false
  35.     tFuel(1)
  36.     turtle.forward()
  37.   else
  38.     tFuel(1)
  39.     turtle.forward()
  40.   end
  41. end
  42.  
  43. local function checkTop()
  44.   if turtle.detectUp() then
  45.     repeat
  46.       tFuel(1)
  47.       repeat
  48.         turtle.digUp()
  49.         sleep(.25)
  50.       until turtle.detectUp() == false
  51.       turtle.up()
  52.     until turtle.detectUp() == false
  53.     repeat
  54.       tFuel(1)
  55.       turtle.down()
  56.     until turtle.detectDown()
  57.   end
  58. end
  59.  
  60. local function uTurn()
  61.   for i = 1, 2 do
  62.     turtle.turnRight()
  63.   end
  64. end
  65.  
  66. local function checkBottom()
  67.   if turtle.detectDown() == false then
  68.     s = 1
  69.     while turtle.getItemCount(s) == 0 do
  70.         s = s + 1
  71.     end
  72.     turtle.select(s)
  73.     turtle.placeDown()
  74.   end
  75. end
  76.  
  77. local function mineLine()
  78.   for i = 1, length do
  79.     tFuel(1)
  80.     digMove()
  81.     checkTop()
  82.     checkBottom()
  83.   end
  84. end
  85.  
  86. -- Main Script
  87.  
  88. for i = 1, width do
  89.   mineLine()
  90.   if turnFlag then
  91.     turtle.turnRight()
  92.     digMove()
  93.     checkTop()
  94.     checkBottom()
  95.     turtle.turnRight()
  96.     turnFlag = false
  97.   else
  98.     turtle.turnLeft()
  99.     digMove()
  100.     checkTop()
  101.     checkBottom()
  102.     turtle.turnLeft()
  103.     turnFlag = true
  104.   end
  105. end
RAW Paste Data