Advertisement
Farmer_GPSY

Mines hole

Oct 29th, 2023 (edited)
898
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.95 KB | Source Code | 1 0
  1. local width = 10 -- Number of horizontal rows
  2. local depth = 10 -- Length of each row
  3. local height = 100 -- Number of vertical layers
  4. local currentLayer = 0 -- Current layer the turtle is on
  5.  
  6. function checkFuel()
  7.     if turtle.getFuelLevel() < 10 then
  8.         print("Refueling...")
  9.         turtle.select(1)  -- Assuming fuel is in the first slot
  10.         turtle.refuel(1)  -- Refuels using 1 item
  11.     end
  12. end
  13.  
  14. function depositItems()
  15.     print("Depositing items...")
  16.    
  17.     -- If the turtle is not on the first layer, move up to the first layer
  18.     for i = 1, currentLayer do
  19.         turtle.up()
  20.     end
  21.  
  22.     turtle.turnLeft()
  23.     turtle.turnLeft()
  24.    
  25.     for i = 2, 16 do -- Slot 1 is for fuel, so we start from 2
  26.         turtle.select(i)
  27.         turtle.drop()
  28.     end
  29.    
  30.     turtle.select(1)
  31.     turtle.turnRight()
  32.     turtle.turnRight()
  33.  
  34.     -- Move back down to the original layer
  35.     for i = 1, currentLayer do
  36.         turtle.down()
  37.     end
  38. end
  39.  
  40. function returnToLayerStart()
  41.     if width % 2 == 0 then  -- If we finished on an even row
  42.         turtle.forward()
  43.         turtle.turnRight()
  44.         for i = 1, depth - 1 do
  45.             turtle.forward()
  46.         end
  47.         turtle.turnRight()
  48.     else  -- We finished on an odd row
  49.         turtle.turnLeft()
  50.         for i = 1, depth - 1 do
  51.             turtle.forward()
  52.         end
  53.         turtle.turnLeft()
  54.     end
  55. end
  56.  
  57. function digLayer()
  58.     for w = 1, width do
  59.         for d = 1, depth do
  60.             checkFuel()
  61.  
  62.             while turtle.detect() do
  63.                 turtle.dig()
  64.             end
  65.            
  66.             if d < depth or w < width then  -- Avoid forward movement at the end of each width and the very last block of the layer
  67.                 turtle.forward()
  68.             end
  69.  
  70.             if turtle.getItemCount(16) > 0 then  -- If the last slot in inventory is filled
  71.                 depositItems()
  72.             end
  73.         end
  74.  
  75.         if w < width then  -- Not the last row
  76.             if w % 2 == 0 then  -- For even rows
  77.                 turtle.turnLeft()
  78.                 turtle.dig()
  79.                 turtle.forward()
  80.                 turtle.turnLeft()
  81.             else  -- For odd rows
  82.                 turtle.turnRight()
  83.                 turtle.dig()
  84.                 turtle.forward()
  85.                 turtle.turnRight()
  86.             end
  87.         end
  88.     end
  89.     returnToLayerStart()
  90.    
  91.      -- Deposit items and check fuel once the turtle is back at the starting position
  92.     depositItems()
  93.     checkFuel()
  94.  
  95.  
  96.      -- Increase current layer count
  97.     currentLayer = currentLayer + 1
  98.    
  99.     -- At the end of the layer, dig the block below and move down
  100.     if turtle.detectDown() then
  101.         turtle.digDown()
  102.     end
  103.     turtle.down()
  104. end
  105.  
  106.  
  107. function startStripMine()
  108.     for h = 1, height do
  109.         print("Mining layer number " .. h)
  110.         digLayer()
  111.     end
  112.  
  113.     print("Finished strip mining!")
  114. end
  115.  
  116. startStripMine()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement