Maengorn

kinetic test

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