Someoneawesome78

BetterTunnel.lua

Dec 18th, 2020 (edited)
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.32 KB | None | 0 0
  1. --function declarations
  2. function fuelTurtle(needed)
  3.     turtle.select(1)
  4.     --Check if first slot has fuel
  5.     if not turtle.refuel(0) then
  6.         print("Waiting for Fuel in slot 1")
  7.         --Wait for fuel
  8.         while not turtle.refuel(0) do
  9.             sleep(1)
  10.         end
  11.     end
  12.  
  13.     --refuel until good
  14.     while needed >= turtle.getFuelLevel() do
  15.         turtle.refuel(1)
  16.     end
  17. end --End of Fuel Turtle
  18.  
  19. function digFront()
  20.     while turtle.detect() do
  21.         turtle.dig()
  22.         sleep(0.5)
  23.     end
  24. end
  25.  
  26. function digUp()
  27.     while turtle.detectUp() do
  28.         turtle.digUp()
  29.         sleep(0.5)
  30.     end
  31. end
  32.  
  33. --main
  34. --Get input
  35. local distance, width, height = ...
  36.  
  37. print("I shall commence mining")
  38.  
  39. --Turn input to numbers
  40. distance = tonumber(distance)
  41. width = tonumber(width)
  42. height = tonumber(height)
  43.  
  44. --If the turtle is facing right currently
  45. rightFacing = true
  46.  
  47. --Repeats for distances down lane
  48. for x = distance, 1, -1 do
  49.     --Check for fuel
  50.     local fuelNeeded = width * height
  51.  
  52.     if fuelNeeded >= turtle.getFuelLevel() then
  53.         fuelTurtle(fuelNeeded + width)
  54.     end
  55.  
  56.     local heightLeft = height - 1
  57.  
  58.     --Commit mining
  59.     --Dig block in front
  60.     digFront()
  61.     turtle.forward()
  62.  
  63.     if rightFacing then
  64.         turtle.turnRight()
  65.     else
  66.         turtle.turnLeft()
  67.     end
  68.    
  69.  
  70.     heightLeft = height
  71.     --Goes along height
  72.     while heightLeft > 0 do
  73.         --Goes along width
  74.         for move = width - 1, 1, -1 do
  75.             --Mines block in front, and top if appropiate and move forward
  76.             if heightLeft > 1 then
  77.                 digUp()
  78.             end
  79.             digFront()
  80.             turtle.forward()
  81.         end
  82.  
  83.         if heightLeft > 1 then
  84.             digUp()
  85.         end
  86.  
  87.         --Set to mined height
  88.         heightLeft = heightLeft - 2
  89.  
  90.         --Checks if there is height left, then go up there
  91.         if heightLeft >= 1 then
  92.             turtle.up()
  93.             digUp()
  94.             turtle.up()
  95.         end
  96.         turtle.turnRight()
  97.         turtle.turnRight()
  98.  
  99.         rightFacing = not rightFacing
  100.     end
  101.  
  102.     --Face Wall
  103.     if rightFacing then
  104.         turtle.turnLeft()
  105.     else
  106.         turtle.turnRight()
  107.     end
  108.    
  109.     for h = height - 1, 1, -1 do
  110.         turtle.down()
  111.     end
  112. end
  113. print("Done!")
Add Comment
Please, Sign In to add comment