Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --FORWARD, RIGHT, BACK, LEFT
- possibleDirections = {1, 2, 3, 4}
- currXYZF = {0, 4, 0, 1}
- maxSupport = 25
- function setXYZ(newXYZ)
- currXYZF[1] = newXYZ[1]
- currXYZF[2] = newXYZ[2]
- currXYZF[3] = newXYZ[3]
- end
- function setOrientation(newOrientation)
- currXYZF[4] = newOrientation
- end
- function adjustOrientation(turnDir)
- currentIndex = currXYZF[4]
- if turnDir == "left" then
- newIndex = (currentIndex - 1) % 4
- elseif turnDir == "right" then
- newIndex = (currentIndex + 1) % 4
- end
- setOrientation(newIndex)
- if turnDir == "left" then
- turtle.turnLeft()
- elseif turnDir == "right" then
- turtle.turnRight()
- end
- end
- function faceOrientation(desiredOrientation)
- requiredChange = desiredOrientation - currXYZF[4]
- if requiredChange == 0 then
- return
- elseif requiredChange > 0 then
- changeSign = "right"
- elseif requiredChange < 0 then
- changeSign = "left"
- end
- for _ = 1, math.abs(requiredChange) do
- adjustOrientation(changeSign)
- end
- end
- function moveDirection(moveFunc, detectFunc, digFunc, attackFunc, maxDigStack, newX, newY, newZ)
- local moveSuccess = moveFunc()
- if not moveSuccess then
- local digCount = 0
- local digSuccess = digFunc()
- moveSuccess = moveFunc()
- while not moveSuccess and digCount < maxDigStack do
- if detectFunc() then
- digFunc()
- digCount = digCount + 1
- else
- attackFunc()
- end
- movementSuccess = moveFunc()
- end
- end
- currXYZF[1] = newX
- currXYZF[2] = newY
- currXYZF[3] = newZ
- end
- function moveForward()
- local newX, newZ
- local currentOrientation = currXYZF[4]
- if currentOrientation == 1 then
- newZ = currXYZF[3] + 1
- newX = currXYZF[1]
- elseif currentOrientation == 2 then
- newZ = currXYZF[3]
- newX = currXYZF[1] - 1
- elseif currentOrientation == 3 then
- newZ = currXYZF[3] - 1
- newX = currXYZF[1]
- elseif currentOrientation == 4 then
- newZ = currXYZF[3]
- newX = currXYZF[1] + 1
- end
- moveDirection(turtle.forward, turtle.detect, turtle.dig, turtle.attack, maxSupport, newX, currXYZF[2], newZ)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement