Advertisement
CelticCoder

turtleToCords

Oct 4th, 2023 (edited)
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.65 KB | None | 0 0
  1. os.loadAPI("setNorth.lua")
  2.  
  3.  
  4. function setVariables(newDiffX, newDiffY, newDiffZ, newNegX, newNegY, newNegZ)
  5.     diffX = newDiffX
  6.     diffY = newDiffY
  7.     diffZ = newDiffZ
  8.     negX = newNegX
  9.     negY = newNegY
  10.     negZ = newNegZ
  11. end
  12.  
  13. function calculateTwoDVariables(targetX, targetZ, deltaX, deltaZ)
  14.     diffX = targetX - deltaX
  15.     diffZ = targetZ - deltaZ
  16.     negX = diffX / math.abs(diffX)
  17.     negZ = diffZ / math.abs(diffZ)
  18. end
  19.  
  20. function toTravelHeight()
  21.     turtle.equipLeft()
  22.     local alphaX, alphaY, alphaZ = gps.locate()
  23.     turtle.equipLeft()
  24.     if alphaY < 250 then
  25.         for increment = alphaY, 250 do
  26.             turtle.digUp()
  27.             turtle.up()
  28.         end
  29.     elseif alphaY > 250 then
  30.         for increment = 1, alphaY - 250 do
  31.             turtle.digDown()
  32.             turtle.down()
  33.         end
  34.     end
  35. end
  36.  
  37. function xMovement(diffX, negX)
  38.     if negX < 0 then
  39.         turtle.turnLeft()
  40.         turtle.turnLeft()
  41.     end
  42.    
  43.     for increment = 1, math.abs(diffX) do
  44.         turtle.dig()
  45.         turtle.forward()
  46.     end
  47.    
  48.     if negX < 0 then
  49.         turtle.turnLeft()
  50.         turtle.turnLeft()
  51.     end
  52. end
  53.  
  54. function zMovement(diffZ, negZ)
  55.     if negZ > 0 then
  56.         turtle.turnRight()
  57.     else
  58.         turtle.turnLeft()
  59.     end
  60.    
  61.     for increment = 1, math.abs(diffZ) do
  62.         turtle.dig()
  63.         turtle.forward()
  64.     end
  65. end
  66.  
  67. function yMovement(diffY, negY)
  68.     for increment = 1, math.abs(diffY) do
  69.         if negY < 0 then
  70.             turtle.digUp()
  71.             turtle.up()
  72.         else
  73.             turtle.digDown()
  74.             turtle.down()
  75.         end
  76.     end
  77. end
  78.  
  79. function xMineMovement(diffX, negX)
  80.     if negX < 0 then
  81.         turtle.turnLeft()
  82.         turtle.turnLeft()
  83.     end
  84.    
  85.     for increment = 1, math.abs(diffX) do
  86.         turtle.dig()
  87.         turtle.forward()
  88.         turtle.digUp()
  89.     end
  90.    
  91.     if negX < 0 then
  92.         turtle.turnLeft()
  93.         turtle.turnLeft()
  94.     end
  95. end
  96.  
  97. function zMineMovement(diffZ, negZ)
  98.     if negZ > 0 then
  99.         turtle.turnRight()
  100.     else
  101.         turtle.turnLeft()
  102.     end
  103.    
  104.     for increment = 1, math.abs(diffZ) do
  105.         turtle.dig()
  106.         turtle.forward()
  107.         turtle.digUp()
  108.     end
  109. end
  110.  
  111. function toCordsSkybox(newDiffX, newDiffY, newDiffZ, newNegX, newNegY, newNegZ)
  112.     setVariables(newDiffX, newDiffY, newDiffZ, newNegX, newNegY, newNegZ)
  113.     toTravelHeight()
  114.     setNorth.lookNorth()
  115.     xMovement(diffX, negX)
  116.     zMovement(diffZ, negZ)
  117.     setNorth.lookNorth()
  118.     yMovement(diffY, negY)
  119. end
  120.  
  121. function toCordsMine(newDiffX, newDiffY, newDiffZ, newNegX, newNegY, newNegZ)
  122.     setVariables(newDiffX, newDiffY, newDiffZ, newNegX, newNegY, newNegZ)
  123.     setNorth.lookNorth()
  124.     xMineMovement(diffX, negX)
  125.     zMineMovement(diffZ, negZ)
  126.     setNorth.lookNorth()
  127.     yMovement(diffY, negY)
  128. end
  129.  
  130. function twoDMove(targetX, targetZ, deltaX, deltaZ)
  131.     calculateTwoDVariables(targetX, targetZ, deltaX, deltaZ)
  132.     setNorth.lookNorth()
  133.     xMovement(diffX, negX)
  134.     zMovement(diffZ, negZ)
  135. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement