cul8ter

fly.lua

Nov 15th, 2021 (edited)
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.32 KB | None | 0 0
  1. local modules = peripheral.find("neuralInterface")
  2. if not modules then
  3.     error("Must have a neural interface", 0)
  4. end
  5. if not modules.hasModule("plethora:sensor") then error("Must have a sensor", 0) end
  6. if not modules.hasModule("plethora:scanner") then error("Must have a scanner", 0) end
  7. if not modules.hasModule("plethora:introspection") then error("Must have an introspection module", 0) end
  8. if not modules.hasModule("plethora:kinetic", 0) then error("Must have a kinetic agument", 0) end
  9. local meta = {}
  10. meta.motionY=0
  11. local hover = false
  12. parallel.waitForAny(
  13.     function()
  14.         while true do
  15.             local event, key = os.pullEvent()
  16.             if event == "key" and key == keys.o then
  17.                 -- The O key launches you high into the air.
  18.                 modules.launch(0, -90, 3)
  19.             elseif event == "key" and key == keys.p then
  20.                 -- The P key launches you a little into the air.
  21.                 modules.launch(0, -90, 1)
  22.             elseif event == "key" and key == keys.l then
  23.                 -- The l key launches you in whatever direction you are looking.
  24.                 modules.launch(meta.yaw, meta.pitch, 3)
  25.             elseif event == "key" and key == keys.k then
  26.                 -- Holding the K key enables "hover" mode. We disable it when it is released.
  27.                 if not hover then
  28.                     hover = true
  29.                     os.queueEvent("hover")
  30.                 end
  31.             elseif event == "key_up" and key == keys.k then
  32.                 hover = false
  33.             end
  34.         end
  35.     end,
  36.     function()
  37.         while true do
  38.             meta = modules.getMetaOwner()
  39.         end
  40.     end,
  41.     function()
  42.         while true do
  43.             if hover then
  44.                 -- We calculate the required motion we need to take
  45.                 local mY = meta.motionY
  46.                 mY = (mY - 0.138) / 0.8
  47.  
  48.                 -- If it is sufficiently large then we fire ourselves in that direction.
  49.                 if mY > 0.5 or mY < 0 then
  50.                     local sign = 1
  51.                     if mY < 0 then sign = -1 end
  52.                     modules.launch(0, 90 * sign, math.min(4, math.abs(mY)))
  53.                 else
  54.                     sleep(0)
  55.                 end
  56.             else
  57.                 os.pullEvent("hover")
  58.             end
  59.         end
  60.     end,
  61.     function()
  62.         while true do
  63.             local blocks = modules.scan()
  64.             for y = 0, -8, -1 do
  65.                 -- Scan from the current block downwards
  66.                 local block = blocks[1 + (8 + (8 + y)*17 + 8*17^2)]
  67.                 if block.name ~= "minecraft:air" then
  68.                     if meta.motionY < -0.3 then
  69.                         -- If we're moving slowly, then launch ourselves up
  70.                         modules.launch(0, -90, math.min(4, meta.motionY / -0.5))
  71.                     end
  72.                     break
  73.                 end
  74.             end
  75.         end
  76.     end
  77. )
Add Comment
Please, Sign In to add comment