Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local difX = 25
- local difY = 5
- local difZ = 25
- local x = math.random(-difZ,difZ)
- local y = math.random(-difY,difY)
- local z = math.random(-difX,difX)
- local cDir = "north"
- local cY = 0
- local cX = 0
- local cZ = 0
- local home = {0,0,0}
- local blocks = "blocks"
- function turnRight()
- if cDir == "north" then
- cDir = "east"
- elseif cDir == "east" then
- cDir = "south"
- elseif cDir == "south" then
- cDir = "west"
- elseif cDir == "west" then
- cDir = "north"
- else
- print("Error!!")
- end
- turtle.turnRight()
- end
- function turnTo(dir)
- if cDir ~= dir then
- repeat
- turnRight()
- until cDir == dir
- end
- end
- function moveForward()
- if cDir == "north" then
- cX = cX+1
- elseif cDir == "east" then
- cZ = cZ+1
- elseif cDir == "south" then
- cX = cX-1
- elseif cDir == "west" then
- cZ = cZ-1
- else
- print("Error!!")
- end
- while not turtle.forward() do
- turtle.dig()
- end
- end
- function moveUp()
- cY = cY+1
- while not turtle.up() do
- turtle.digUp()
- end
- end
- function moveDown()
- cY = cY-1
- while not turtle.down() do
- turtle.digDown()
- end
- end
- function moveToX(x)
- if cX < x then
- turnTo("north")
- repeat
- moveForward()
- until cX == x
- elseif cX > x then
- turnTo("south")
- repeat
- moveForward()
- until cX == x
- else
- --print("already there")
- end
- end
- function moveToZ(z)
- if cZ < z then
- turnTo("east")
- repeat
- moveForward()
- until cZ == z
- elseif cZ > z then
- turnTo("west")
- repeat
- moveForward()
- until cZ == z
- else
- --print("already there")
- end
- end
- function moveToY(y)
- if cY < y then
- repeat
- moveUp()
- until cY == y
- elseif cY > y then
- repeat
- moveDown()
- until cY == y
- else
- --print("already there")
- end
- end
- function goTo(x, y, z)
- moveToX(x)
- moveToY(y)
- moveToZ(z)
- turnTo("north")
- end
- function sayMoveX()
- if x == 1 or x == -1 then
- blocks = "block"
- else
- blocks = "blocks"
- end
- if x > 0 then
- print("I have moved "..x.." "..blocks.." forward.")
- elseif x < 0 then
- local x = x*-1
- print("I have moved "..x.." "..blocks.." backwards.")
- else
- print("I haven't moved forward or backwards.")
- end
- end
- function sayMoveY()
- if y == 1 or y == -1 then
- blocks = "block"
- else
- blocks = "blocks"
- end
- if y > 0 then
- print("I have moved "..y.." "..blocks.." up.")
- elseif y < 0 then
- local y = y*-1
- print("I have moved "..y.." "..blocks.." down.")
- else
- print("I haven't moved up or down.")
- end
- end
- function sayMoveZ()
- if z == 1 or z == -1 then
- blocks = "block"
- else
- blocks = "blocks"
- end
- if z > 0 then
- print("I have moved "..z.." "..blocks.." to the right.")
- elseif z < 0 then
- local z = z*-1
- print("I have moved "..z.." "..blocks.." to the left.")
- else
- print("I haven't moved to the right or left.")
- end
- end
- function sayMoves()
- sayMoveX()
- sayMoveY()
- sayMoveZ()
- end
- goTo(x,y,z)
- sayMoves()
- --sleep(5)
- --goTo(home[1], home[2], home[3])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement