Tjakka5

Untitled

Dec 12th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 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. local function harvest()
  69. for i = 1, 7 do
  70. turtle.forward()
  71. end
  72.  
  73. turtle.turnLeft()
  74.  
  75. for i = 1, 7 do
  76. turtle.forward()
  77. end
  78.  
  79. turtle.turnRight()
  80. end
  81.  
  82. harvest()
  83.  
  84. local x, y, z = turtle.getPosition()
  85. print(x, y, z)
  86.  
  87. local ox, oz = turtle.getOrientation()
  88. print(ox, oz)
  89.  
  90.  
  91.  
Advertisement
Add Comment
Please, Sign In to add comment