View difference between Paste ID: xEDKdM85 and rtdRFN3G
SHOW: | | - or go back to the newest paste.
1
if peripheral.getType "back" ~= "neuralInterface" then error "for neural interfaces with kinetic augments and stuff, silly potato" end
2
3-
os.loadAPI "metaowner.lua"
3+
local user = "gollark"
4-
metaowner.upgrade(modules)
4+
if settings.get "flight_user" then user = flight_user end
5
if potatOS and potatOS.registry then 
6
	user = potatOS.registry.get "flight_user"
7-
    local meta = modules.getMetaOwner()
7+
	if not user then error "Please set your username with `est flight_user [username]`" end
8-
    
8+
end
9-
    while meta.isSneaking or meta.isFlying do
9+
10-
        meta = modules.getMetaOwner()
10+
11-
        modules.launch(meta.yaw, meta.pitch, 4)
11+
local function length(x, y, z)
12-
        sleep(0.1)
12+
	return math.sqrt(x * x + y * y + z * z)
13
end
14
15-
    if meta.motionY < -0.8 then
15+
local function round(num, dp)
16-
        modules.launch(0, 270, 2)
16+
	local mult = 10^(dp or 0)
17
	return math.floor(num * mult + 0.5) / mult
18
end
19-
    sleep(0.4)
19+
20
local canvas = modules.canvas()
21
22
-- Backported from Opus Neural ElytraFly since it has a nicer implementation than I do
23
local function display(meta)
24
  if canvas then
25
	local w, h = canvas.getSize()
26
    if not canvas.group then
27
      canvas.group = canvas.addGroup({ w - 80, 15 })
28
      canvas.group.addRectangle(0, 0, 60, 30, 0x00000033)
29
      canvas.pitch = canvas.group.addText({ 4, 5 }, '') -- , 0x202020FF)
30
      canvas.pitch.setShadow(true)
31
      canvas.pitch.setScale(.75)
32
      canvas.group2 = canvas.addGroup({ w - 10, 15 })
33
      canvas.group2.addLines(
34
        { 0,   0 },
35
        { 0, 180 },
36
        { 5, 180 },
37
        { 5,   0 },
38
        0x202020FF,
39
        2)
40
      canvas.meter = canvas.group2.addRectangle(0, 0, 5, 1)
41
    end
42
    local size = math.abs(meta.pitch) -- math.ceil(math.abs(meta.pitch) / 9)
43
    local y = 0
44
    local color = 0x202020FF
45
    if meta.pitch < 0 then
46
      y = size
47
      color = 0x808080FF
48
    end
49
    canvas.meter.setPosition(0, 90 - y)
50
    canvas.meter.setSize(5, size)
51
    canvas.meter.setColor(color)
52
    canvas.pitch.setText(string.format('Pitch: %s\nMotion Y: %s\nSpeed: %s',
53
      math.floor(-meta.pitch),
54
      round(meta.motionY, 2),
55
      round(length(meta.motionX, meta.motionY, meta.motionZ), 2)))
56
  end
57
end
58
59
--[[
60
local function pad(s, i)
61
	return ("%s %s%.1f"):format(s, i >= 0 and "+" or "", i)
62
end
63
64
local overlay = {
65
	function(meta) return pad("X:", meta.motionX) end,
66
	function(meta) return pad("Y:", meta.motionY) end,
67
	function(meta) return pad("Z:", meta.motionZ) end,
68
	function(meta) return pad("  ", length(meta.motionX, meta.motionY, meta.motionZ)) end,
69
	function(meta) return pad("P:", meta.power) end
70
}
71
72
local objects
73
local function draw_overlay(meta)
74
	if not objects then
75
		objects = {}
76
		local w, h = canv.getSize()
77
		for ix in pairs(overlay) do
78
			objects[ix] = canv.addText({w - 40, ix * 10 + 5}, "")
79
			objects[ix].setColor(0xFFFFFFFF)
80
		end
81
	end
82
	for ix, f in pairs(overlay) do
83
		objects[ix].setText(f(meta))
84
	end
85
end
86
]]
87
88
local function get_power(meta)
89
	local power = 4
90
	if meta.isElytraFlying or meta.isFlying then power = 1 end
91
	if meta.isSneaking then power = 4 end
92
	if _G.tps then
93
		power = power * (20 / _G.tps)
94
	end
95
	return math.min(power, 4)
96
end
97
98
local function get_meta()
99
	local meta = modules.getMetaByName(user)
100
	meta.power = get_power(meta)
101
	display(meta)
102
	return meta
103
end
104
105
while true do
106
	local meta = get_meta()
107
  
108
	while (not _G.stop_flight) and (meta.isSneaking or meta.isFlying or meta.isElytraFlying) do
109
		modules.launch(meta.yaw, meta.pitch, meta.power)
110
		sleep(0.1)
111
		meta = get_meta()
112
	end
113
114
	if meta.motionY < -0.8 then
115
		modules.launch(0, 270, meta.power / 2)
116
	end
117
118
	sleep(0.4)
119
end