Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Infinite loop for breaking blocks in front of the turtle
- -- Usage: break_loop [delay] [--rclick] [--block <blockname>] [--exclude <blockname>]
- -- delay: optional delay in seconds between break attempts (default: 0.1)
- -- --rclick: perform right-click (turtle.place()) instead of breaking blocks
- -- --block <blockname>: only break blocks that contain the specified name (e.g., "log" matches all log types)
- -- --exclude <blockname>: break everything except blocks that contain the specified name
- local args = {...}
- local delay = 0.1
- local rightClick = false
- local targetBlock = nil
- local excludeBlock = nil
- -- Parse arguments
- local i = 1
- while i <= #args do
- local arg = args[i]
- if arg == "--rclick" then
- rightClick = true
- elseif arg == "--block" then
- i = i + 1
- if i <= #args then
- targetBlock = string.lower(args[i])
- else
- print("Error: --block requires a block name")
- return
- end
- elseif arg == "--exclude" then
- i = i + 1
- if i <= #args then
- excludeBlock = string.lower(args[i])
- else
- print("Error: --exclude requires a block name")
- return
- end
- elseif tonumber(arg) then
- delay = tonumber(arg)
- end
- i = i + 1
- end
- -- Validate arguments
- if targetBlock and excludeBlock then
- print("Error: Cannot use both --block and --exclude at the same time")
- return
- end
- if rightClick then
- print("Starting infinite right-click loop...")
- print("Delay between right-clicks: " .. delay .. " seconds")
- else
- print("Starting infinite block breaking loop...")
- if targetBlock then
- print("Only breaking blocks containing: " .. targetBlock)
- elseif excludeBlock then
- print("Breaking all blocks except those containing: " .. excludeBlock)
- end
- print("Delay between breaks: " .. delay .. " seconds")
- end
- print("Press Ctrl+T to stop")
- -- Function to safely break a block in front
- local function breakBlockInFront()
- if turtle.detect() then
- local success, data = turtle.inspect()
- if success and data then
- local blockName = data.name or "unknown block"
- local lowerBlockName = string.lower(blockName)
- -- If targetBlock is specified, check if the block matches
- if targetBlock then
- if not string.find(lowerBlockName, targetBlock) then
- print("Skipping: " .. blockName .. " (not matching '" .. targetBlock .. "')")
- return false
- end
- end
- -- If excludeBlock is specified, check if the block should be excluded
- if excludeBlock then
- if string.find(lowerBlockName, excludeBlock) then
- print("Skipping: " .. blockName .. " (excluded by '" .. excludeBlock .. "')")
- return false
- end
- end
- print("Breaking: " .. blockName)
- turtle.dig()
- return true
- else
- -- If inspection fails but filters are specified, don't dig
- if targetBlock or excludeBlock then
- print("Cannot inspect block - skipping due to block filter")
- return false
- end
- turtle.dig() -- Try to dig anyway if inspection fails and no filter
- return true
- end
- end
- return false
- end
- -- Function to perform right-click (place block)
- local function rightClickInFront()
- local success = turtle.place()
- if success then
- print("Right-clicked (placed block)")
- return true
- else
- print("Right-click failed (no item or space blocked)")
- return false
- end
- end
- -- Main infinite loop
- local actionCount = 0
- while true do
- local success = false
- if rightClick then
- success = rightClickInFront()
- if success then
- actionCount = actionCount + 1
- print("Right-clicks performed: " .. actionCount)
- end
- else
- success = breakBlockInFront()
- if success then
- actionCount = actionCount + 1
- print("Blocks broken: " .. actionCount)
- else
- print("No block detected in front")
- end
- end
- -- Wait for the specified delay
- sleep(delay)
- end
Advertisement
Add Comment
Please, Sign In to add comment