Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- stair_or_turn_stone_bricks.lua
- -- Loop:
- -- - If no block ahead: place STONE BRICKS below, move forward, continue.
- -- - If block ahead: place STONE BRICKS below, move up, if block ahead then turn 180°, place STONE BRICKS, continue; else stop.
- local function selectStoneBricks()
- for s = 1, 16 do
- local d = turtle.getItemDetail(s)
- if d and (d.name == "minecraft:stone_bricks" or (d.displayName and d.displayName:lower() == "stone bricks")) then
- turtle.select(s)
- return true
- end
- end
- return false
- end
- local function placeStoneBricksDown()
- if not selectStoneBricks() then
- print("Out of stone bricks. Stopping.")
- return false
- end
- if not turtle.placeDown() then
- -- If a block is already below, that is fine.
- if not turtle.detectDown() then
- print("Failed to place stone bricks below. Stopping.")
- return false
- end
- end
- return true
- end
- while true do
- if not turtle.detect() then
- -- No block ahead: drop bricks below, step forward
- if not placeStoneBricksDown() then break end
- if not turtle.forward() then
- print("Blocked while moving forward. Stopping.")
- break
- end
- else
- -- Block ahead: drop bricks below, go up
- if not placeStoneBricksDown() then break end
- if not turtle.up() then
- print("Blocked above. Stopping.")
- break
- end
- if turtle.detect() then
- -- Block ahead after moving up: turn around, drop bricks, continue
- turtle.turnLeft(); turtle.turnLeft()
- if not placeStoneBricksDown() then break end
- -- continue loop
- else
- -- No block ahead after moving up: end
- print("Open path found after climbing. Stopping.")
- break
- end
- end
- end
- print("Done.")
Advertisement
Add Comment
Please, Sign In to add comment