Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Mining version 2.0.0")
- -- Configuration
- local ALLOWED_BLOCKS = {
- "minecraft:gravel",
- "minecraft:andesite"
- }
- local MAX_Y = 70
- local FUEL_ITEM = "minecraft:coal" -- Replace with your fuel item ID
- -- Function to check if a block is in the allowed list
- local function isAllowedBlock(blockName)
- for _, allowed in ipairs(ALLOWED_BLOCKs) do
- if blockName == allowed then
- return true
- end
- end
- return false
- end
- -- Function to refuel the turtle
- local function refuel()
- print("Attempting to refuel...")
- local fuelSlot = -1
- for i = 1, turtle.getInventorySize() do
- local item = turtle.getItemDetail(i)
- if item and item.name == FUEL_ITEM then
- fuelSlot = i
- break
- end
- end
- if fuelSlot ~= -1 then
- turtle.select(fuelSlot)
- if turtle.refuel() then
- print("Refueled successfully.")
- return true
- else
- print("Failed to refuel.")
- return false
- end
- else
- print("No fuel found in inventory.")
- return false
- end
- end
- -- Function to check and mine a block if it's exposed and allowed
- local function checkAndMine(direction)
- local success, data = turtle.inspect(direction)
- if success then
- if isAllowedBlock(data.name) then
- local successUp, dataUp = turtle.inspectUp()
- if successUp and dataUp.name == "minecraft:air" then
- print("Mining " .. data.name .. " " .. direction)
- turtle.dig(direction)
- -- Optional: You could add a short sleep here
- -- os.sleep(0.1)
- return true -- Mined a block
- end
- end
- end
- return false -- Did not mine a block
- end
- -- Main mining loop
- local radius = 0
- local mined_in_cycle = 0
- while turtle.getYLevel() <= MAX_Y do
- print("Current Y: " .. turtle.getYLevel())
- mined_in_cycle = 0
- -- Move outwards in a spiral pattern
- for i = 1, radius * 2 + 1 do
- -- Check fuel before moving
- if turtle.getFuelLevel() < 50 then -- Refuel when fuel is low
- if not refuel() then
- print("Cannot refuel, stopping.")
- return
- end
- end
- -- Check and mine in front
- if checkAndMine("forward") then
- mined_in_cycle = mined_in_cycle + 1
- end
- -- Move forward, avoiding non-allowed blocks
- local success, data = turtle.inspect("forward")
- if success and not isAllowedBlock(data.name) and data.name ~= "minecraft:air" then
- print("Blocked by non-allowed block, skipping forward movement.")
- else
- if not turtle.forward() then
- print("Failed to move forward, potentially blocked.")
- -- You might want to add more sophisticated blocking handling here
- -- For now, we just print a message and continue
- end
- end
- end
- -- Turn and increase radius
- turtle.turnLeft()
- if radius > 0 then
- for i = 1, radius * 2 + 1 do
- -- Check fuel before moving
- if turtle.getFuelLevel() < 50 then
- if not refuel() then
- print("Cannot refuel, stopping.")
- return
- end
- end
- -- Check and mine in front
- if checkAndMine("forward") then
- mined_in_cycle = mined_in_cycle + 1
- end
- -- Move forward, avoiding non-allowed blocks
- local success, data = turtle.inspect("forward")
- if success and not isAllowedBlock(data.name) and data.name ~= "minecraft:air" then
- print("Blocked by non-allowed block, skipping forward movement.")
- else
- if not turtle.forward() then
- print("Failed to move forward, potentially blocked.")
- end
- end
- end
- turtle.turnLeft()
- end
- radius = radius + 1
- -- Check if no blocks were mined in the last cycle (might be stuck or done)
- if mined_in_cycle == 0 and radius > 1 then
- print("No allowed blocks mined in the last cycle. Potentially done or stuck.")
- -- You might want to add more sophisticated logic here to break out of the loop
- -- For now, we'll let it continue, but it might just keep spiraling
- end
- end
- print("Reached maximum Y level or stopped.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement