ColdIV

ClearArea

Jun 9th, 2021 (edited)
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.86 KB | None | 0 0
  1. local args = {...}
  2. local height = tonumber(args[1])
  3. local length = tonumber(args[2])
  4. local width = tonumber(args[3])
  5.  
  6. print ("Height: " .. height .. "\n")
  7. print ("Length: " .. length .. "\n")
  8. print ("Width: " .. width .. "\n")
  9.  
  10. local data = turtle.getItemDetail(1) -- fuel slot 1
  11. local fuelType = data.name
  12.  
  13. function checkFuel ()
  14.     if turtle.getFuelLevel() <= 0 then
  15.         print ("no fuel\n")
  16.         for i = 1, 16, 1 do
  17.             if turtle.getItemDetail(i).name == fuelType then
  18.                 turtle.select(i)
  19.                 turtle.refuel()
  20.                 print ("refuel\n")
  21.                 return true
  22.             end
  23.         end
  24.  
  25.         print ("out of fuel\n")
  26.         return false
  27.     end
  28.    
  29.     return true
  30. end
  31.  
  32. function dig ()
  33.     while turtle.detect() do
  34.         turtle.dig()
  35.     end
  36. end
  37.  
  38. function digUp ()
  39.     while turtle.detectUp() do
  40.         turtle.digUp()
  41.     end
  42. end
  43.  
  44. function digDown ()
  45.     while turtle.detectDown() do
  46.         turtle.digDown()
  47.     end
  48. end
  49.  
  50. local len = 0
  51. local last = "down"
  52. local lastT = "left"
  53.  
  54. checkFuel()
  55.  
  56. dig()
  57. turtle.forward()
  58. len = len + 1
  59.  
  60. while true do
  61.     checkFuel()
  62.    
  63.     for i = 1, height - 1, 1 do
  64.         if last == "down" then
  65.             digUp()
  66.             turtle.up()
  67.         else
  68.             digDown()
  69.             turtle.down()
  70.         end  
  71.     end
  72.    
  73.     if last == "down" then last = "up"
  74.     else last = "down" end
  75.    
  76.     if len < length then
  77.         dig()
  78.         turtle.forward()
  79.         len = len + 1
  80.     elseif len >= length then
  81.         len = 1
  82.         if lastT == "left" then turtle.turnRight()
  83.         else turtle.turnLeft() end
  84.         dig()
  85.         turtle.forward()
  86.         if lastT == "left" then
  87.             turtle.turnRight()
  88.             lastT = "right"
  89.         else
  90.             turtle.turnLeft()
  91.             lastT = "left"
  92.         end
  93.     end
  94. end
Add Comment
Please, Sign In to add comment