Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Input turtle X coord")
- xCoord = read()
- xCoord = tonumber(xCoord)
- print("Input turtle Y coord")
- yCoord = read()
- yCoord = tonumber(yCoord)
- print("Input turtle Z coord")
- zCoord = read()
- zCoord = tonumber(zCoord)
- print("Input turtle direction NSEW")
- facing = read()
- function stepForwards(int)
- local i = 0
- repeat
- if turtle.forward() then
- i = i + 1
- if facing == "N" then
- zCoord = zCoord - 1
- elseif facing == "E" then
- xCoord = xCoord + 1
- elseif facing == "S" then
- zCoord = zCoord + 1
- elseif facing == "W" then
- xCoord = xCoord - 1
- end
- else
- turtle.attack()
- turtle.dig()
- end
- until i == int
- end
- function stepDown(int)
- local i = 0
- repeat
- if turtle.down() then
- i = i + 1
- yCoord = yCoord - 1
- else
- turtle.attackDown()
- turtle.digDown()
- end
- until i == int
- end
- function stepUp(int)
- local i = 0
- repeat
- if turtle.up() then
- i = i + 1
- yCoord = yCoord + 1
- else
- turtle.attackUp()
- turtle.digUp()
- end
- until i == int
- end
- function rotateNorth()
- if facing == "N" then
- facing = "N"
- return true
- elseif facing == "E" then
- facing = "N"
- turtle.turnLeft()
- return true
- elseif facing == "S" then
- facing = "N"
- turtle.turnLeft()
- turtle.turnLeft()
- return true
- elseif facing == "W" then
- facing = "N"
- turtle.turnRight()
- return true
- end
- end
- function rotateEast()
- if facing == "N" then
- facing = "E"
- turtle.turnRight()
- return true
- elseif facing == "E" then
- facing = "E"
- return true
- elseif facing == "S" then
- facing = "E"
- turtle.turnLeft()
- return true
- elseif facing == "W" then
- facing = "E"
- turtle.turnRight()
- turtle.turnRight()
- return true
- end
- end
- function rotateSouth()
- if facing == "N" then
- facing = "S"
- turtle.turnLeft()
- turtle.turnLeft()
- return true
- elseif facing == "E" then
- facing = "S"
- turtle.turnRight()
- return true
- elseif facing == "S" then
- facing = "S"
- return true
- elseif facing == "W" then
- facing = "S"
- turtle.turnLeft()
- return true
- end
- end
- function rotateWest()
- if facing == "N" then
- facing = "W"
- turtle.turnLeft()
- return true
- elseif facing == "E" then
- facing = "W"
- turtle.turnRight()
- turtle.turnRight()
- return true
- elseif facing == "S" then
- facing = "W"
- turtle.turnRight()
- return true
- elseif facing == "W" then
- facing = "W"
- return true
- end
- end
- while true do
- print("input targetX")
- targetX = read()
- targetX = tonumber(targetX)
- print("input targetY")
- targetY = read()
- targetY = tonumber(targetY)
- print("input targetZ")
- targetZ = read()
- targetZ = tonumber(targetZ)
- if xCoord < targetX then
- rotateEast()
- stepForwards(targetX - xCoord)
- elseif xCoord > targetX then
- rotateWest()
- stepForwards(xCoord - targetX)
- end
- if yCoord > targetY then
- stepDown(yCoord - targetY)
- elseif yCoord < targetY then
- stepUp(targetY - yCoord)
- end
- if zCoord > targetZ then
- rotateNorth()
- stepForwards(zCoord - targetZ)
- elseif zCoord < targetZ then
- rotateSouth()
- stepForwards(targetZ - zCoord)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement