Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x = 0
- y = 0
- z = 0
- --Facing direction start with 1 being 90 degrees left. 2 is backwards etc.
- --By convention we will always face 0 when not doing something.
- --We will take this to be right.
- facing = 0
- function turnLeft()
- facing = facing - 1
- if facing < 0 then
- facing = facing + 4
- end
- turtle.turnLeft()
- end
- function turnRight()
- facing = facing + 1
- if facing > 3 then
- facing = facing - 4
- end
- turtle.turnRight()
- end
- function faceXLeft()
- if facing == 0 then
- turnLeft()
- turnLeft()
- elseif facing == 1 then
- turnRight()
- elseif facing == 2 then
- return
- elseif facing == 3 then
- turnLeft()
- end
- end
- function faceXRight()
- if facing == 0 then
- return
- elseif facing == 1 then
- turnLeft()
- elseif facing == 2 then
- turnLeft()
- turnLeft()
- elseif facing == 3 then
- turnRight()
- end
- end
- function faceYUp()
- if facing == 0 then
- turnLeft()
- elseif facing == 1 then
- turnLeft()
- turnLeft()
- elseif facing == 2 then
- turnRight()
- elseif facing == 3 then
- return
- end
- end
- function faceYDown()
- if facing == 0 then
- turnRight()
- elseif facing == 1 then
- return
- elseif facing == 2 then
- turnLeft()
- elseif facing == 3 then
- turnLeft()
- turnLeft()
- end
- end
- function zUp()
- while turtle.detectUp() do
- while not turtle.digUp() do
- --loop
- end
- end
- while not turtle.up() do
- turtle.digUp()
- end
- z = z + 1
- end
- function zDown()
- while turtle.detectDown() do
- while not turtle.digDown() do
- --loop
- end
- end
- while not turtle.down() do
- turtle.digDown()
- end
- z = z - 1
- end
- function xLeft()
- faceXLeft()
- while turtle.dig() do
- while not turtle.dig() do
- --loop
- end
- end
- while not turtle.forward() do
- turtle.dig()
- end
- x = x - 1
- end
- function xRight()
- faceXRight()
- while turtle.detect() do
- while not turtle.dig() do
- --loop
- end
- end
- while not turtle.forward() do
- turtle.dig()
- end
- x = x + 1
- end
- function yUp()
- faceYUp()
- while turtle.detect() do
- while not turtle.dig() do
- --loop
- end
- end
- while not turtle.forward() do
- turtle.dig()
- end
- y = y + 1
- end
- function yDown()
- faceYDown()
- while turtle.detect() do
- while not turtle.dig() do
- --loop
- end
- end
- while not turtle.forward() do
- turtle.dig()
- end
- y = y - 1
- end
- function zUpIsBlock()
- return turtle.detectUp()
- end
- function zDownIsBlock()
- return turtle.detectDown()
- end
- function xLeftIsBlock()
- faceXLeft()
- return turtle.detect()
- end
- function xRightIsBlock()
- faceXRight()
- return turtle.detect()
- end
- function yUpIsBlock()
- faceYUp()
- return turtle.detect()
- end
- function yDownIsBlock()
- faceYDown()
- return turtle.detect()
- end
- --find direction to start
- while turtle.detect() do
- turtle.turnLeft()
- end
- facing = 0
- --we're assumed to now be facing to the right
- --Now well get the params from the spacing.
- --Its just a box. We assume to be on x center and edge on y and z.
- --First we get to and edge
- while not xRightIsBlock() do
- xRight()
- end
- --Now at right end
- maxX = x
- while not xLeftIsBlock() do
- xLeft()
- end
- minX = x
- --Now we in top left
- minZ = 0
- maxZ = 10
- --square
- minY = -(maxX - minX)
- maxY = y
- --start (from top left)
- --We are on the minX and minY in top left
- while y > minY do
- while x < maxX do
- --Mine from far left to right
- if z == minZ then
- while z < maxZ do
- zUp()
- end
- else
- while z > minZ do
- zDown()
- end
- end
- xRight()
- end
- --now at far right
- yDown()
- if z == minZ then
- while z < maxZ do
- zUp()
- end
- else
- while z > minZ do
- zDown()
- end
- end
- if y == minY then
- break
- end
- while x > minX do
- --Mine from far right to left
- if z == minZ then
- while z < maxZ do
- zUp()
- end
- else
- while z > minZ do
- zDown()
- end
- end
- xLeft()
- end
- --now on far left
- yDown()
- end
- while z > minZ do
- zDown()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement