Tjakka5

Untitled

Dec 12th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. do -- Robot state
  2. local turtleState = {
  3. position = {x = 85, y = 66, z = 165},
  4. orientation = {x = 0, z = -1},
  5. }
  6.  
  7. local _turtleForward = turtle.forward
  8. turtle.forward = function()
  9. turtleState.position.x = turtleState.position.x + turtleState.orientation.x
  10. turtleState.position.z = turtleState.position.z + turtleState.orientation.z
  11.  
  12. return _turtleForward()
  13. end
  14.  
  15. local _turtleBack = turtle.back
  16. turtle.back = function(...)
  17. turtleState.position.x = turtleState.position.x - turtleState.orientation.x
  18. turtleState.position.z = turtleState.position.z - turtleState.orientation.z
  19.  
  20. return _turtleBack(...)
  21. end
  22.  
  23. local _turtleUp = turtle.up
  24. turtle.up = function(...)
  25. turtleState.position.y = turtleState.position.y + 1
  26.  
  27. return _turtleUp(...)
  28. end
  29.  
  30. local _turtleDown = turtle.down
  31. turtle.down = function(...)
  32. turtleState.position.y = turtleState.position.y - 1
  33.  
  34. return _turtleDown(...)
  35. end
  36.  
  37. local _turtleTurnLeft = turtle.turnLeft
  38. turtle.turnLeft = function(...)
  39. local oldOrientationX = turtleState.orientation.x
  40. local oldOrientationZ = turtleState.orientation.z
  41.  
  42. turtleState.orientation.x = oldOrientationZ
  43. turtleState.orientation.z = -oldOrientationX
  44.  
  45. return _turtleTurnLeft(...)
  46. end
  47.  
  48. local _turtleTurnRight = turtle.turnRight
  49. turtle.turnRight = function(...)
  50. local oldOrientationX = turtleState.orientation.x
  51. local oldOrientationZ = turtleState.orientation.z
  52.  
  53. turtleState.orientation.x = -oldOrientationZ
  54. turtleState.orientation.z = oldOrientationX
  55.  
  56. return _turtleTurnRight(...)
  57. end
  58.  
  59. turtle.getPosition = function()
  60. return turtleState.position.x, turtleState.position.y, turtleState.position.z
  61. end
  62.  
  63. turtle.getOrientation = function()
  64. return turtleState.orientation.x, turtleState.orientation.z
  65. end
  66. end
  67.  
  68. turtle.forward()
  69. turtle.forward()
  70. turtle.turnLeft()
  71. turtle.back()
  72. turtle.up()
  73.  
  74. local x, y, z = turtle.getPosition()
  75. print(x, y, z)
  76.  
  77. local ox, oz = turtle.getOrientation()
  78. print(ox, oz)
  79.  
  80.  
  81.  
Advertisement
Add Comment
Please, Sign In to add comment