Advertisement
tahg

turtle

May 15th, 2013
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. local s = turtle.select
  2. local f = turtle.forward
  3. local b = turtle.back
  4. local l = turtle.turnLeft
  5. local r = turtle.turnRight
  6. local u = turtle.up
  7. local d = turtle.down
  8.  
  9. local function select(num)
  10. if num == nil then
  11. return turtle.slot
  12. else
  13. rawset(turtle, "slot", num)
  14. return s(num)
  15. end
  16. end
  17. local function forward()
  18. if f() then
  19. rawset(turtle, "x", turtle.x + turtle.dirX)
  20. rawset(turtle, "z", turtle.z + turtle.dirZ)
  21. return true
  22. end
  23. return false
  24. end
  25. local function back()
  26. if b() then
  27. rawset(turtle, "x", turtle.x - turtle.dirX)
  28. rawset(turtle, "z", turtle.z - turtle.dirZ)
  29. return true
  30. end
  31. return false
  32. end
  33. local function left()
  34. local dirX, dirZ = turtle.dirZ, -turtle.dirX
  35. rawset(turtle, "dirX", dirX)
  36. rawset(turtle, "dirZ", dirZ)
  37. return l()
  38. end
  39. local function right()
  40. local dirX, dirZ = -turtle.dirZ, turtle.dirX
  41. rawset(turtle, "dirX", dirX)
  42. rawset(turtle, "dirZ", dirZ)
  43. return r()
  44. end
  45. local function up()
  46. if u() then
  47. rawset(turtle, "y", turtle.y + 1)
  48. return true
  49. end
  50. return false
  51. end
  52. local function down()
  53. if d() then
  54. rawset(turtle, "y", turtle.y - 1)
  55. return true
  56. end
  57. return false
  58. end
  59. local function loc()
  60. return turtle.x, turtle.y, turtle.z
  61. end
  62. local function dir()
  63. return turtle.dirX, turtle.dirZ
  64. end
  65. local function rotate(x, z)
  66. if math.abs(x - z) == 1 and
  67. math.abs(x + z) == 1 then
  68. while turtle.dirX ~= x or
  69. turtle.dirZ ~= z do
  70. right()
  71. end
  72. end
  73. end
  74. local function init(x, y, z, dirX, dirZ)
  75. rawset(turtle, "x", x)
  76. rawset(turtle, "y", y)
  77. rawset(turtle, "z", z)
  78. rawset(turtle, "dirX", dirX)
  79. rawset(turtle, "dirZ", dirZ)
  80. end
  81. local function front()
  82. x, y, z = turtle.loc()
  83. dirX, dirZ = turtle.dir()
  84. return x + dirX, y, z + dirZ
  85. end
  86. rawset(turtle, "select", select)
  87. rawset(turtle, "forward", forward)
  88. rawset(turtle, "back", back)
  89. rawset(turtle, "turnLeft", left)
  90. rawset(turtle, "turnRight", right)
  91. rawset(turtle, "up", up)
  92. rawset(turtle, "down", down)
  93. rawset(turtle, "loc", loc)
  94. rawset(turtle, "dir", dir)
  95. rawset(turtle, "rotate", rotate)
  96. rawset(turtle, "init", init)
  97. rawset(turtle, "front", front)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement