Advertisement
phupqpr

25x25x25

Sep 7th, 2023 (edited)
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.27 KB | None | 0 0
  1. -- A program to make turtle computercraft dig a 25x25x25 hole
  2. -- The turtle should start at the top left corner of the hole
  3. -- The turtle should have enough fuel and a chest in slot 1
  4.  
  5. local length = 25 -- The length of the hole
  6. local width = 25 -- The width of the hole
  7. local depth = 25 -- The depth of the hole
  8.  
  9. -- A function to check if the turtle has enough fuel
  10. local function checkFuel()
  11.   if turtle.getFuelLevel() < 10 then -- If the fuel level is less than 10
  12.     print("Low fuel. Refueling...") -- Print a message
  13.     turtle.select(16) -- Select the last slot
  14.     if turtle.refuel(1) then -- Try to refuel with one item
  15.       print("Refueled.") -- Print a message
  16.     else -- If refueling failed
  17.       print("No fuel. Please insert fuel in slot 16.") -- Print a message
  18.       while not turtle.refuel(1) do -- Wait until refueling succeeds
  19.         os.sleep(1) -- Sleep for one second
  20.       end
  21.       print("Refueled.") -- Print a message
  22.     end
  23.   end
  24. end
  25.  
  26. -- A function to dig forward and move forward
  27. local function digForward()
  28.   checkFuel() -- Check the fuel level
  29.   while turtle.detect() do -- While there is a block in front
  30.     turtle.dig() -- Dig the block
  31.   end
  32.   turtle.forward() -- Move forward
  33. end
  34.  
  35. -- A function to dig down and move down
  36. local function digDown()
  37.   checkFuel() -- Check the fuel level
  38.   while turtle.detectDown() do -- While there is a block below
  39.     turtle.digDown() -- Dig the block
  40.   end
  41.   turtle.down() -- Move down
  42. end
  43.  
  44. -- A function to dig up and move up
  45. local function digUp()
  46.   checkFuel() -- Check the fuel level
  47.   while turtle.detectUp() do -- While there is a block above
  48.     turtle.digUp() -- Dig the block
  49.   end
  50.   turtle.up() -- Move up
  51. end
  52.  
  53. -- A function to turn around
  54. local function turnAround()
  55.   turtle.turnLeft() -- Turn left
  56.   turtle.turnLeft() -- Turn left again
  57. end
  58.  
  59. -- A function to place a chest and empty the inventory
  60. local function emptyInventory()
  61.   print("Inventory full. Emptying...") -- Print a message
  62.   turtle.select(1) -- Select the first slot (chest)
  63.   while not turtle.placeDown() do -- While placing the chest fails
  64.     digDown() -- Dig down and move down
  65.   end
  66.   for i = 2, 16 do -- For each slot except the first one (chest)
  67.     turtle.select(i) -- Select the slot
  68.     turtle.dropDown() -- Drop the item into the chest
  69.   end
  70.   turtle.select(1) -- Select the first slot (chest)
  71.   digUp() -- Dig up and move up (back to original position)
  72. end
  73.  
  74. -- A function to check if the inventory is full
  75. local function checkInventory()
  76.   if turtle.getItemCount(16) > 0 then -- If the last slot is not empty
  77.     emptyInventory() -- Empty the inventory into a chest below
  78.   end
  79. end
  80.  
  81. -- Start digging the hole
  82.  
  83. print("Starting to dig...") -- Print a message
  84.  
  85. for i = 1, depth do -- For each layer of depth
  86.  
  87.   for j = 1, width do -- For each row of width
  88.    
  89.     for k = 1, length - 1 do -- For each column of length except the last one
  90.      
  91.       digForward() -- Dig forward and move forward
  92.      
  93.       checkInventory() -- Check if the inventory is full
  94.      
  95.     end
  96.    
  97.     if j < width then -- If this is not the last row
  98.      
  99.       if j % 2 == 0 then -- If this is an even row
  100.        
  101.         turtle.turnLeft() -- Turn left
  102.        
  103.         digForward() -- Dig forward and move forward
  104.        
  105.         checkInventory() -- Check if the inventory is full
  106.        
  107.         turtle.turnLeft() -- Turn left
  108.        
  109.       else -- If this is an odd row
  110.        
  111.         turtle.turnRight() -- Turn right
  112.        
  113.         digForward() -- Dig forward and move forward
  114.        
  115.         checkInventory() -- Check if the inventory is full
  116.        
  117.         turtle.turnRight() -- Turn right
  118.        
  119.       end
  120.      
  121.     elseif i < depth then -- If this is the last row but not the last layer
  122.      
  123.       turnAround() -- Turn around
  124.      
  125.       for l = 1, length -1 do -- For each column of length except the first one
  126.        
  127.         digForward() -- Dig forward and move forward
  128.        
  129.         checkInventory() -- Check if the inventory is full
  130.        
  131.       end
  132.      
  133.       digDown() -- Dig down and move down
  134.      
  135.       checkInventory() -- Check if the inventory is full
  136.      
  137.     end
  138.    
  139.   end
  140.  
  141. end
  142.  
  143. print("Finished digging.") -- Print a message
  144.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement