Advertisement
tahg

Untitled

Oct 2nd, 2012
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. disk/turtle
  2.  
  3. local s = turtle.select
  4. local f = turtle.forward
  5. local b = turtle.back
  6. local l = turtle.turnLeft
  7. local r = turtle.turnRight
  8. local u = turtle.up
  9. local d = turtle.down
  10.  
  11. local function select(num)
  12. if num == nil then
  13. return turtle.slot
  14. else
  15. rawset(turtle, "slot", num)
  16. return s(num)
  17. end
  18. end
  19. local function forward()
  20. if f() then
  21. rawset(turtle, "x", turtle.x + turtle.dirX)
  22. rawset(turtle, "z", turtle.z + turtle.dirZ)
  23. return true
  24. end
  25. return false
  26. end
  27. local function back()
  28. if b() then
  29. rawset(turtle, "x", turtle.x - turtle.dirX)
  30. rawset(turtle, "z", turtle.z - turtle.dirZ)
  31. return true
  32. end
  33. return false
  34. end
  35. local function left()
  36. local dirX, dirZ = turtle.dirZ, -turtle.dirX
  37. rawset(turtle, "dirX", dirX)
  38. rawset(turtle, "dirZ", dirZ)
  39. return l()
  40. end
  41. local function right()
  42. local dirX, dirZ = -turtle.dirZ, turtle.dirX
  43. rawset(turtle, "dirX", dirX)
  44. rawset(turtle, "dirZ", dirZ)
  45. return r()
  46. end
  47. local function up()
  48. if u() then
  49. rawset(turtle, "y", turtle.y + 1)
  50. return true
  51. end
  52. return false
  53. end
  54. local function down()
  55. if d() then
  56. rawset(turtle, "y", turtle.y - 1)
  57. return true
  58. end
  59. return false
  60. end
  61. local function loc()
  62. return turtle.x, turtle.y, turtle.z
  63. end
  64. local function dir()
  65. return turtle.dirX, turtle.dirZ
  66. end
  67. local function rotate(x, z)
  68. if math.abs(x - z) == 1 and
  69. math.abs(x + z) == 1 then
  70. while turtle.dirX ~= x or
  71. turtle.dirZ ~= z do
  72. right()
  73. end
  74. end
  75. end
  76. local function init(x, y, z, dirX, dirZ)
  77. rawset(turtle, "x", x)
  78. rawset(turtle, "y", y)
  79. rawset(turtle, "z", z)
  80. rawset(turtle, "dirX", dirX)
  81. rawset(turtle, "dirZ", dirZ)
  82. end
  83. local function front()
  84. x, y, z = turtle.loc()
  85. dirX, dirZ = turtle.dir()
  86. return x + dirX, y, z + dirZ
  87. end
  88. rawset(turtle, "select", select)
  89. rawset(turtle, "forward", forward)
  90. rawset(turtle, "back", back)
  91. rawset(turtle, "turnLeft", left)
  92. rawset(turtle, "turnRight", right)
  93. rawset(turtle, "up", up)
  94. rawset(turtle, "down", down)
  95. rawset(turtle, "loc", loc)
  96. rawset(turtle, "dir", dir)
  97. rawset(turtle, "rotate", rotate)
  98. rawset(turtle, "init", init)
  99. rawset(turtle, "front", front)
  100.  
  101.  
  102. -----------------------------------
  103.  
  104.  
  105. disk/deployGPS (slots: drive | computer | modem | floppy)
  106.  
  107. local function setup()
  108. turtle.forward()
  109. turtle.select(1)
  110. turtle.place()
  111. turtle.select(4)
  112. turtle.drop()
  113. local x, y, z = turtle.front()
  114. f = fs.open("disk/startup", "w")
  115. f.write("shell.run(\"gps\", \"host\", "..x..", "..(y + 1)..", "..z..")")
  116. f.close()
  117. turtle.up()
  118. turtle.select(2)
  119. turtle.place()
  120. turtle.up()
  121. turtle.select(3)
  122. turtle.place()
  123. turtle.down()
  124. peripheral.call("front", "reboot")
  125. turtle.down()
  126. turtle.suck()
  127. turtle.select(1)
  128. turtle.dig()
  129. turtle.back()
  130. end
  131.  
  132. setup()
  133. turtle.turnRight()
  134. turtle.turnRight()
  135. setup()
  136. turtle.up()
  137. turtle.up()
  138. turtle.turnRight()
  139. setup()
  140. turtle.turnRight()
  141. turtle.turnRight()
  142. setup()
  143. turtle.turnLeft()
  144. turtle.down()
  145. turtle.down()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement