Advertisement
CelticCoder

setNorth

Nov 12th, 2023 (edited)
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.23 KB | None | 0 0
  1. function directionCheck()
  2.     gpscords = {}
  3.     turtle.equipLeft()
  4.     alphaX, alphaY, alphaZ = gps.locate()
  5.     turtle.equipLeft()
  6.     turtle.dig()
  7.     turtle.forward()
  8.     turtle.equipLeft()
  9.     betaX, betaY, betaZ = gps.locate()
  10.     turtle.equipLeft()
  11.     turtle.back()
  12.     return alphaX, alphaY, alphaZ, betaX, betaY, betaZ
  13. end
  14. function pointNorth(newalphaX, newalphaY, newalphaZ, newbetaX, newbetaY, newbetaZ)
  15.     alphaX = newalphaX
  16.     alphaY = newalphaY
  17.     alphaZ = newalphaZ
  18.     betaX = newbetaX
  19.     betaY = newbetaY
  20.     betaZ = newbetaZ
  21.     if betaX > alphaX then
  22.         --positive x direction
  23.     elseif betaX < alphaX then
  24.         --negative x direction
  25.         turtle.turnLeft()
  26.         turtle.turnLeft()
  27.     elseif betaZ > alphaZ then
  28.         --positive z direction
  29.         turtle.turnLeft()
  30.     elseif betaZ < alphaZ then
  31.         --negative z direction
  32.         turtle.turnRight()
  33.     end
  34. end
  35.  
  36. function returnDirection(newalphaX, newalphaY, newalphaZ, newbetaX, newbetaY, newbetaZ)
  37.     alphaX = newalphaX
  38.     alphaY = newalphaY
  39.     alphaZ = newalphaZ
  40.     betaX = newbetaX
  41.     betaY = newbetaY
  42.     betaZ = newbetaZ
  43.     if betaX > alphaX then
  44.         --positive x direction
  45.         return "north"
  46.     elseif betaX < alphaX then
  47.         --negative x direction
  48.         return "south"
  49.     elseif betaZ > alphaZ then
  50.         --positive z direction
  51.         return "west"
  52.     elseif betaZ < alphaZ then
  53.         --negative z direction
  54.         return "east"
  55.     end
  56. end
  57.  
  58. function setDirection(direct)
  59.     if direct == "north" then
  60.         --positive x direction
  61.        
  62.     elseif direct == "south" then
  63.         --negative x direction
  64.         turtle.turnLeft()
  65.         turtle.turnLeft()
  66.     elseif direct == "west" then
  67.         --positive z direction
  68.         turtle.turnLeft()
  69.     elseif direct == "east" then
  70.         --negative z direction
  71.         turtle.turnRight()
  72.     end
  73. end
  74.  
  75. function lookNorth()
  76.     newalphaX, newalphaY, newalphaZ, newbetaX, newbetaY, newbetaZ = directionCheck()
  77.     pointNorth(newalphaX, newalphaY, newalphaZ, newbetaX, newbetaY, newbetaZ)
  78. end
  79.  
  80. function getDirection()
  81.     alphaX, alphaY, alphaZ, betaX, betaY, betaZ = directionCheck()
  82.     return returnDirection(alphaX, alphaY, alphaZ, betaX, betaY, betaZ)
  83. end
  84.  
  85. function oppDirection(direct)
  86.     if direct == "north" then
  87.         return "south"
  88.     elseif direct == "south" then
  89.         return "north"
  90.     elseif direct == "west" then
  91.         return "east"
  92.     elseif direct == "east" then
  93.         return "west"  
  94.     end
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement