roger109z

fly

May 26th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. --v3
  2. local modules = peripheral.find("neuralInterface")
  3. if not modules then
  4. error("Must have a neural interface", 0)
  5. end
  6. if not modules.hasModule("plethora:sensor") then error("Must have a sensor", 0) end
  7. if not modules.hasModule("plethora:scanner") then error("Must have a scanner", 0) end
  8. if not modules.hasModule("plethora:introspection") then error("Must have an introspection module", 0) end
  9. if not modules.hasModule("plethora:kinetic", 0) then error("Must have a kinetic agument", 0) end
  10. local meta = {}
  11. local hover = false
  12. local down = false
  13. local up = false
  14. local forward = false
  15. local back = false
  16. local right = false
  17. local left = false
  18. parallel.waitForAny(
  19. function()
  20. while true do
  21. local event, key = os.pullEvent()
  22. if event == "key" and key == keys.c then
  23. -- The O key launches you high into the air.
  24. modules.launch(0, -90, 3)
  25. elseif event == "key" and key == keys.z then
  26. -- The P key launches you a little into the air.
  27. modules.launch(0, -90, 1)
  28. elseif event == "key" and key == keys.f then
  29. -- The l key launches you in whatever direction you are looking.
  30. modules.launch(meta.yaw, meta.pitch, 3)
  31. elseif event == "key" and key == keys.x then
  32. -- Holding the K key enables "hover" mode. We disable it when it is released.
  33. if not hover then
  34. hover = true
  35. print("hover active")
  36. os.queueEvent("hover")
  37. else
  38. hover = false
  39. print("hover disabled")
  40. end
  41. elseif event == "key" and key == keys.space then
  42. if not up then
  43. up = true
  44. end
  45. elseif event == "key_up" and key == keys.space then
  46. up = false
  47. elseif event == "key" and key == keys.leftShift then
  48. if not down then
  49. down = true
  50. end
  51. elseif event == "key_up" and key == keys.leftShift then
  52. down = false
  53. --
  54. elseif event == "key" and key == keys.w then
  55. if not forward then
  56. forward = true
  57. end
  58. elseif event == "key_up" and key == keys.w then
  59. forward = false
  60. elseif event == "key" and key == keys.s then
  61. if not back then
  62. back = true
  63. end
  64. elseif event == "key_up" and key == keys.s then
  65. back = false
  66. elseif event == "key" and key == keys.d then
  67. if not right then
  68. right = true
  69. end
  70. elseif event == "key_up" and key == keys.right then
  71. right = false
  72. elseif event == "key" and key == keys.left then
  73. if not left then
  74. left = true
  75. end
  76. elseif event == "key_up" and key == keys.left then
  77. left = false
  78. end
  79. end
  80. end,
  81. function()
  82. while true do
  83. meta = modules.getMetaOwner()
  84. end
  85. end,
  86. function()
  87. while true do
  88. if hover then
  89. -- We calculate the required motion we need to take
  90. local mY = meta.motionY
  91. mY = ( (mY - 0.138) / 0.8 ) + .007
  92.  
  93. -- If it is sufficiently large then we fire ourselves in that direction.
  94. if up and not down and hover then
  95. modules.launch(0, -90, 1)
  96. elseif down and not up and hover then
  97. modules.launch(0, 90, 1)
  98. end
  99. if forward then
  100. modules.launch(meta.yaw, 0, .5)
  101. end
  102. if mY > 0.5 or mY < 0 then
  103. local sign = 1
  104. if mY < 0 then sign = -1 end
  105. modules.launch(0, 90*sign, math.min(4, math.abs(mY)))
  106. else
  107. sleep(0)
  108. end
  109. else
  110. os.pullEvent("hover")
  111. end
  112. end
  113. end,
  114. function()
  115. while true do
  116. local blocks = modules.scan()
  117. for y = 0, -8, -1 do
  118. -- Scan from the current block downwards
  119. local block = blocks[1 + (8 + (8 + y)*17 + 8*17^2)]
  120. if block.name ~= "minecraft:air" then
  121. if meta.motionY < -0.3 then
  122. -- If we're moving slowly, then launch ourselves up
  123. modules.launch(0, -90, math.min(4, meta.motionY / -0.5))
  124. end
  125. break
  126. end
  127. end
  128. end
  129. end
  130. )
Add Comment
Please, Sign In to add comment