Advertisement
dan330

Untitled

May 7th, 2025 (edited)
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.52 KB | None | 0 0
  1. print("Mining version 2.0.0")
  2.  
  3. -- Configuration
  4. local ALLOWED_BLOCKS = {
  5.     "minecraft:gravel",
  6.     "minecraft:andesite"
  7. }
  8. local MAX_Y = 70
  9. local FUEL_ITEM = "minecraft:coal" -- Replace with your fuel item ID
  10.  
  11. -- Function to check if a block is in the allowed list
  12. local function isAllowedBlock(blockName)
  13.     for _, allowed in ipairs(ALLOWED_BLOCKs) do
  14.         if blockName == allowed then
  15.             return true
  16.         end
  17.     end
  18.     return false
  19. end
  20.  
  21. -- Function to refuel the turtle
  22. local function refuel()
  23.     print("Attempting to refuel...")
  24.     local fuelSlot = -1
  25.     for i = 1, turtle.getInventorySize() do
  26.         local item = turtle.getItemDetail(i)
  27.         if item and item.name == FUEL_ITEM then
  28.             fuelSlot = i
  29.             break
  30.         end
  31.     end
  32.  
  33.     if fuelSlot ~= -1 then
  34.         turtle.select(fuelSlot)
  35.         if turtle.refuel() then
  36.             print("Refueled successfully.")
  37.             return true
  38.         else
  39.             print("Failed to refuel.")
  40.             return false
  41.         end
  42.     else
  43.         print("No fuel found in inventory.")
  44.         return false
  45.     end
  46. end
  47.  
  48. -- Function to check and mine a block if it's exposed and allowed
  49. local function checkAndMine(direction)
  50.     local success, data = turtle.inspect(direction)
  51.     if success then
  52.         if isAllowedBlock(data.name) then
  53.             local successUp, dataUp = turtle.inspectUp()
  54.             if successUp and dataUp.name == "minecraft:air" then
  55.                 print("Mining " .. data.name .. " " .. direction)
  56.                 turtle.dig(direction)
  57.                 -- Optional: You could add a short sleep here
  58.                 -- os.sleep(0.1)
  59.                 return true -- Mined a block
  60.             end
  61.         end
  62.     end
  63.     return false -- Did not mine a block
  64. end
  65.  
  66. -- Main mining loop
  67. local radius = 0
  68. local mined_in_cycle = 0
  69.  
  70. while turtle.getYLevel() <= MAX_Y do
  71.     print("Current Y: " .. turtle.getYLevel())
  72.     mined_in_cycle = 0
  73.  
  74.     -- Move outwards in a spiral pattern
  75.     for i = 1, radius * 2 + 1 do
  76.         -- Check fuel before moving
  77.         if turtle.getFuelLevel() < 50 then -- Refuel when fuel is low
  78.             if not refuel() then
  79.                 print("Cannot refuel, stopping.")
  80.                 return
  81.             end
  82.         end
  83.  
  84.         -- Check and mine in front
  85.         if checkAndMine("forward") then
  86.             mined_in_cycle = mined_in_cycle + 1
  87.         end
  88.  
  89.         -- Move forward, avoiding non-allowed blocks
  90.         local success, data = turtle.inspect("forward")
  91.         if success and not isAllowedBlock(data.name) and data.name ~= "minecraft:air" then
  92.              print("Blocked by non-allowed block, skipping forward movement.")
  93.         else
  94.              if not turtle.forward() then
  95.                  print("Failed to move forward, potentially blocked.")
  96.                  -- You might want to add more sophisticated blocking handling here
  97.                  -- For now, we just print a message and continue
  98.              end
  99.         end
  100.     end
  101.  
  102.     -- Turn and increase radius
  103.     turtle.turnLeft()
  104.  
  105.     if radius > 0 then
  106.         for i = 1, radius * 2 + 1 do
  107.             -- Check fuel before moving
  108.             if turtle.getFuelLevel() < 50 then
  109.                 if not refuel() then
  110.                     print("Cannot refuel, stopping.")
  111.                     return
  112.                 end
  113.             end
  114.  
  115.             -- Check and mine in front
  116.             if checkAndMine("forward") then
  117.                 mined_in_cycle = mined_in_cycle + 1
  118.             end
  119.  
  120.              -- Move forward, avoiding non-allowed blocks
  121.             local success, data = turtle.inspect("forward")
  122.             if success and not isAllowedBlock(data.name) and data.name ~= "minecraft:air" then
  123.                  print("Blocked by non-allowed block, skipping forward movement.")
  124.             else
  125.                  if not turtle.forward() then
  126.                      print("Failed to move forward, potentially blocked.")
  127.                  end
  128.             end
  129.         end
  130.         turtle.turnLeft()
  131.     end
  132.  
  133.     radius = radius + 1
  134.  
  135.     -- Check if no blocks were mined in the last cycle (might be stuck or done)
  136.     if mined_in_cycle == 0 and radius > 1 then
  137.          print("No allowed blocks mined in the last cycle. Potentially done or stuck.")
  138.          -- You might want to add more sophisticated logic here to break out of the loop
  139.          -- For now, we'll let it continue, but it might just keep spiraling
  140.     end
  141. end
  142.  
  143. print("Reached maximum Y level or stopped.")
  144.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement