Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Safe forward movement: if blocked by an entity or obstacle,
- -- try to dig if it's a block, or wait if it's an entity.
- function safeForward()
- while not turtle.forward() do
- local success, data = turtle.inspect()
- if success then
- turtle.dig()
- else
- -- Likely an entity in the way; wait for it to clear.
- os.sleep(0.5)
- end
- end
- end
- -- Functions for lateral movement (keeping original direction)
- function moveLeft(n)
- turtle.turnLeft()
- for i = 1, n do
- safeForward()
- end
- turtle.turnRight()
- end
- function moveRight(n)
- turtle.turnRight()
- for i = 1, n do
- safeForward()
- end
- turtle.turnLeft()
- end
- -- Function to "flatten" a column:
- -- Assumes the turtle is at ground level.
- -- It first moves up 2 blocks (ensuring a 3-block high space: floor + 2 air blocks),
- -- then moves back down. If there is no block underfoot, it places one from the inventory.
- function flattenColumn()
- -- Clear the vertical space (upper 2 blocks)
- for i = 1, 2 do
- if turtle.detectUp() then
- turtle.digUp()
- end
- turtle.up()
- end
- -- Move back down to ground level
- turtle.down()
- turtle.down()
- -- If no block is detected below, place a block from the inventory.
- if not turtle.detectDown() then
- for slot = 1, 16 do
- turtle.select(slot)
- if turtle.getItemCount() > 0 then
- turtle.placeDown()
- break
- end
- end
- end
- end
- -- Function to check for a deep drop (more than 5 blocks)
- -- The turtle temporarily moves forward, then descends counting missing blocks.
- -- Afterwards, it returns to the original position.
- function isDeepDropAhead()
- if not turtle.forward() then
- -- Movement blocked, so assume no drop.
- return false
- end
- local depth = 0
- while depth <= 5 and not turtle.detectDown() do
- depth = depth + 1
- turtle.down()
- end
- -- Return to the original level.
- for i = 1, depth do
- turtle.up()
- end
- turtle.back()
- return depth > 5
- end
- -- Function for one step: flatten the corridor section and then move forward.
- -- The corridor is considered 4 blocks wide (current block plus 3 blocks to the right).
- function flattenStep()
- if isDeepDropAhead() then
- print("Deep drop ahead - stopping.")
- return false
- end
- local corridorWidth = 4
- for offset = 0, corridorWidth - 1 do
- if offset > 0 then
- moveRight(offset)
- end
- flattenColumn()
- if offset > 0 then
- moveLeft(offset)
- end
- end
- safeForward()
- return true
- end
- -- Main function: while fuel is available, perform the flattening step by step.
- function flattenTerrain()
- while turtle.getFuelLevel() > 0 do
- if not flattenStep() then
- break
- end
- end
- end
- flattenTerrain()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement