Advertisement
Guest User

simplefly

a guest
Feb 22nd, 2022
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.99 KB | None | 0 0
  1. local modules = peripheral.wrap "back"
  2.  
  3. local function length(x, y, z)
  4.     return math.sqrt(x * x + y * y + z * z)
  5. end
  6.  
  7. local function round(num, dp)
  8.     local mult = 10^(dp or 0)
  9.     return math.floor(num * mult + 0.5) / mult
  10. end
  11.  
  12. local canvas = modules.canvas()
  13.  
  14. -- Backported from Opus Neural ElytraFly since it has a nicer implementation than I do
  15. local function display(meta)
  16.   if canvas then
  17.     local w, h = canvas.getSize()
  18.     if not canvas.group then
  19.       canvas.group = canvas.addGroup({ w - 80, 15 })
  20.       canvas.group.addRectangle(0, 0, 60, 30, 0x00000033)
  21.       canvas.pitch = canvas.group.addText({ 4, 5 }, '') -- , 0x202020FF)
  22.       canvas.pitch.setShadow(true)
  23.       canvas.pitch.setScale(.75)
  24.       canvas.group2 = canvas.addGroup({ w - 10, 15 })
  25.       canvas.group2.addLines(
  26.         { 0,   0 },
  27.         { 0, 180 },
  28.         { 5, 180 },
  29.         { 5,   0 },
  30.         0x202020FF,
  31.         2)
  32.       canvas.meter = canvas.group2.addRectangle(0, 0, 5, 1)
  33.     end
  34.     local size = math.abs(meta.pitch) -- math.ceil(math.abs(meta.pitch) / 9)
  35.     local y = 0
  36.     local color = 0x202020FF
  37.     if meta.pitch < 0 then
  38.       y = size
  39.       color = 0x808080FF
  40.     end
  41.     canvas.meter.setPosition(0, 90 - y)
  42.     canvas.meter.setSize(5, size)
  43.     canvas.meter.setColor(color)
  44.     local my = meta.motionY
  45.     if not meta.isInWater then my = my + 0.0784 end
  46.     canvas.pitch.setText(string.format('Pitch: %s\nMotion Y: %s\nSpeed: %s',
  47.       math.floor(-meta.pitch),
  48.       round(my, 2),
  49.       round(length(meta.motionX, my, meta.motionZ), 2)))
  50.   end
  51. end
  52.  
  53. --[[
  54. local function pad(s, i)
  55.     return ("%s %s%.1f"):format(s, i >= 0 and "+" or "", i)
  56. end
  57.  
  58. local overlay = {
  59.     function(meta) return pad("X:", meta.motionX) end,
  60.     function(meta) return pad("Y:", meta.motionY) end,
  61.     function(meta) return pad("Z:", meta.motionZ) end,
  62.     function(meta) return pad("  ", length(meta.motionX, meta.motionY, meta.motionZ)) end,
  63.     function(meta) return pad("P:", meta.power) end
  64. }
  65.  
  66. local objects
  67. local function draw_overlay(meta)
  68.     if not objects then
  69.         objects = {}
  70.         local w, h = canv.getSize()
  71.         for ix in pairs(overlay) do
  72.             objects[ix] = canv.addText({w - 40, ix * 10 + 5}, "")
  73.             objects[ix].setColor(0xFFFFFFFF)
  74.         end
  75.     end
  76.     for ix, f in pairs(overlay) do
  77.         objects[ix].setText(f(meta))
  78.     end
  79. end
  80. ]]
  81.  
  82. local function get_power(meta)
  83.     local power = 4
  84.     if meta.isElytraFlying or meta.isFlying then power = 1 end
  85.     if meta.isSneaking then power = 4 end
  86.     if _G.tps then
  87.         power = power * (20 / _G.tps)
  88.     end
  89.     return math.min(power, 4)
  90. end
  91.  
  92. local function get_meta()
  93.     local meta = modules.getMetaByName "gollark"
  94.     meta.power = get_power(meta)
  95.     display(meta)
  96.     return meta
  97. end
  98.  
  99. while true do
  100.     local meta = get_meta()
  101.  
  102.     while (not _G.stop_flight) and (meta.isSneaking or meta.isFlying or meta.isElytraFlying) do
  103.         modules.launch(meta.yaw, meta.pitch, meta.power)
  104.         sleep(0.1)
  105.         meta = get_meta()
  106.     end
  107.  
  108.     if meta.motionY < -0.4 then
  109.         modules.launch(0, 270, meta.power / 2)
  110.     end
  111.  
  112.     sleep(0.4)
  113. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement