Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local keepRunning=true
- local borderBlock="minecraft:glass"
- local turnedRightLast=false
- local shouldGoDown=false
- local x=0
- local y=0
- local z=0
- local function goForward() write("F") return turtle.forward() end
- local function turnRight() write("R") turtle.turnRight() end
- local function turnLeft() write("L") turtle.turnLeft() end
- local function detectBorder() local success, data = turtle.inspect() if success then if data.name == borderBlock then return true else return false end end end
- local function detectBorderUp() local success, data = turtle.inspectUp() if success then if data.name == borderBlock then shouldGoDown=true end end end
- local function detectDown() local success, data = turtle.inspectDown() if success then return data.name end end
- local function suckAll () turtle.suck() turtle.suckDown() turtle.suckUp() end
- local function goUp() write("U") y=y+1 return turtle.up() end
- local function goDown() write("D") y=y-1 return turtle.down() end
- local function upOrDown ()
- if detectBorderUp() then
- end
- end
- local function turnAround () turnRight() turnRight() end
- local function detectCorner()
- -- Look forward
- local borderForward = detectBorder()
- -- Look left
- turnLeft()
- local borderLeft = detectBorder()
- -- turn Right and look
- turnRight()
- local borderRight = detectBorder()
- -- turn back left (so we are looking forward)
- turnLeft()
- if (borderForward and borderLeft) or (borderForward and borderRight) then
- if shouldGoDown then
- goDown()
- else
- goUp()
- end
- turnAround()
- end
- end
- while keepRunning do
- while not turtle.detect() do
- -- White we didn't detect anything
- goForward()
- end
- detectCorner()
- end
- -- -- go forward to border
- -- -- at border turn right
- -- -- try to go forward. If not forward, and not at top, go up
- -- if not goForward() then
- -- if detectBorder() then
- -- write("B")
- -- if not turnedRightLast then
- -- write("rt")
- -- if not uTurnRight() then
- -- if not detectedTop then
- -- if not goUp() then
- -- if detectBorderUp() then
- -- detectedTop=true
- -- goDown()
- -- end
- -- else
- -- uTurnRight()
- -- uTurnRight()
- -- end
- -- uTurnLeft()
- -- else
- -- goDown()
- -- end
- -- end
- -- turnedRightLast=true
- -- else
- -- write("lt")
- -- if not uTurnLeft() then
- -- goUp()
- -- uTurnRight()
- -- end
- -- turnedRightLast=false
- -- end
- -- else
- -- turtle.dig()
- -- suckAll()
- -- end
- -- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement