Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------movement library
- curXPos = 0
- curYPos = 0
- curZPos = 0
- orientation = "north"
- forward = function()
- local k = turtle.forward()
- if k == true then
- if orientation == "north" then
- curXPos = curXPos + 1
- elseif orientation == "east" then
- curYPos = curYPos + 1
- elseif orientation == "south" then
- curXPos = curXPos - 1
- elseif orientation == "west" then
- curYPos = curYPos - 1
- end
- end
- return k
- end
- up = function()
- local k = turtle.up()
- if k == true then
- curZPos = curZPos + 1
- end
- return k
- end
- down = function()
- local k = turtle.down()
- if k == true then
- curZPos = curZPos - 1
- end
- return k
- end
- turnLeft = function()
- local k = turtle.turnLeft()
- if orientation == "north" then
- orientation = "west"
- elseif orientation == "west" then
- orientation = "south"
- elseif orientation == "south" then
- orientation = "east"
- elseif orientation == "east" then
- orientation = "north"
- end
- return k
- end
- turnRight = function()
- local k = turtle.turnRight()
- if orientation == "north" then
- orientation = "east"
- elseif orientation == "east" then
- orientation = "south"
- elseif orientation == "south" then
- orientation = "west"
- elseif orientation == "west" then
- orientation = "north"
- end
- return k
- end
- ---------------these functions are useful for specific situations (NOTE: you should probably use faceDirection() instead of turtle.turn as it updates orientation which is relevant for the other functions)
- goHome = function()
- local savedPos = {}
- savedPos.x = curXPos
- savedPos.y = curYPos
- savedPos.z = curZPos
- print("Facing direction: "..orientation)
- if curYPos > 0 then
- faceDirection("west")
- for i=1,savedPos.y do
- forward()
- end
- elseif curYPos < 0 then
- faceDirection("east")
- for i=1,math.abs(savedPos.y) do
- forward()
- end
- end
- if curXPos > 0 then
- faceDirection("south")
- for i=1,savedPos.x do
- forward()
- end
- elseif curXPos < 0 then
- faceDirection("north")
- for i=1,math.abs(savedPos.x) do
- forward()
- end
- end
- end
- faceDirection = function(orientation)
- if orientation == "north" then
- if orientation == "south" then
- for i=1,2 do
- turtle.turnLeft()
- end
- elseif orientation == "east" then
- turtle.turnLeft()
- elseif orientation == "west" then
- turtle.turnRight()
- end
- orientation = "north"
- elseif orientation == "west" then
- if orientation == "south" then
- turtle.turnRight()
- elseif orientation =="east" then
- for i=1,2 do
- turtle.turnLeft()
- end
- elseif orientation == "north" then
- turtle.turnLeft()
- end
- orientation = "west"
- elseif orientation == "south" then
- if orientation == "east" then
- turtle.turnRight()
- elseif orientation == "north" then
- for i=1,2 do
- turtle.turnLeft()
- end
- elseif orientation == "west" then
- turtle.turnLeft()
- end
- orientation = "south"
- elseif orientation == "east" then
- if orientation == "north" then
- turtle.turnRight()
- elseif orientation == "west" then
- for i=1,2 do
- turtle.turnLeft()
- end
- elseif orientation == "south" then
- turtle.turnLeft()
- end
- orientation = "east"
- end
- end
- goToCoords = function(toX, toY, toZ, orientation, coordFirst, coordSecond, coordThird)
- local savedPos = {}
- local changeInPos = {}
- savedPos.toX = toX
- savedPos.toY = toY
- savedPos.toZ = toZ
- savedPos.orient = orientation
- local placeholder = {}
- placeholder.x = math.abs(savedPos.toX - curXPos)
- placeholder.y = math.abs(savedPos.toY - curYPos)
- placeholder.z = math.abs(savedPos.toZ - curZPos)
- if coordFirst == "z" then
- if savedPos.z > curZPos then
- for i=1,placeholder.z do
- turtle.digUp()
- up()
- end
- elseif savedPos.z < curZPos then
- for i=1,placeholder.z do
- down()
- end
- end
- if coordSecond == "y"
- if savedPos.y > curYPos then
- faceDirection("east")
- for i=1, placeholder.y do
- forward()
- end
- elseif savedPos.y < curYPos then
- faceDirection("west")
- for i=1,placeholder.y do
- forward()
- end
- end
- if savedPos.x > curXPos then
- faceDirection("north")
- for i=1,placeholder.x do
- forward()
- end
- elseif savedPos.x < curXPos then
- faceDirection("south")
- for i=1,placeholder.x do
- forward()
- end
- end
- else
- if savedPos.x > curXPos then
- faceDirection("north")
- for i=1,placeholder.x do
- forward()
- end
- elseif savedPos.x < curXPos then
- faceDirection("south")
- for i=1,placeholder.x do
- forward()
- end
- end
- if savedPos.y > curYPos then
- faceDirection("east")
- for i=1, placeholder.y do
- forward()
- end
- elseif savedPos.y < curYPos then
- faceDirection("west")
- for i=1,placeholder.y do
- forward()
- end
- end
- end
- elseif coordFirst == "y"
- if savedPos.y > curYPos then
- faceDirection("east")
- for i=1, placeholder.y do
- forward()
- end
- elseif savedPos.y < curYPos then
- faceDirection("west")
- for i=1,placeholder.y do
- forward()
- end
- end
- if coordSecond == "x" then
- if savedPos.x > curXPos then
- faceDirection("north")
- for i=1,placeholder.x do
- forward()
- end
- elseif savedPos.x < curXPos then
- faceDirection("south")
- for i=1,placeholder.x do
- forward()
- end
- end
- if savedPos.z > curZPos then
- for i=1,placeholder.z do
- turtle.digUp()
- up()
- end
- elseif savedPos.z < curZPos then
- for i=1,placeholder.z do
- down()
- end
- end
- else
- if savedPos.z > curZPos then
- for i=1,placeholder.z do
- turtle.digUp()
- up()
- end
- elseif savedPos.z < curZPos then
- for i=1,placeholder.z do
- down()
- end
- end
- if savedPos.x > curXPos then
- faceDirection("north")
- for i=1,placeholder.x do
- forward()
- end
- elseif savedPos.x < curXPos then
- faceDirection("south")
- for i=1,placeholder.x do
- forward()
- end
- end
- end
- else
- if savedPos.x > curXPos then
- faceDirection("north")
- for i=1,placeholder.x do
- forward()
- end
- elseif savedPos.x < curXPos then
- faceDirection("south")
- for i=1,placeholder.x do
- forward()
- end
- end
- if coordSecond == "y" then
- if savedPos.y > curYPos then
- faceDirection("east")
- for i=1, placeholder.y do
- forward()
- end
- elseif savedPos.y < curYPos then
- faceDirection("west")
- for i=1,placeholder.y do
- forward()
- end
- end
- if savedPos.z > curZPos then
- for i=1,placeholder.z do
- turtle.digUp()
- up()
- end
- elseif savedPos.z < curZPos then
- for i=1,placeholder.z do
- down()
- end
- end
- else
- if savedPos.z > curZPos then
- for i=1,placeholder.z do
- turtle.digUp()
- up()
- end
- elseif savedPos.z < curZPos then
- for i=1,placeholder.z do
- down()
- end
- end
- if savedPos.y > curYPos then
- faceDirection("east")
- for i=1, placeholder.y do
- forward()
- end
- elseif savedPos.y < curYPos then
- faceDirection("west")
- for i=1,placeholder.y do
- forward()
- end
- end
- end
- end
- end
- faceDirection(savedPos.orient)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement