launch control for elytraFly + mirror fixes
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
local Event = require('event')
|
local Event = require('event')
|
||||||
local GPS = require('gps')
|
local GPS = require('gps')
|
||||||
local Point = require('point')
|
local Point = require('point')
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
local Terminal = require('terminal')
|
local Terminal = require('terminal')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
local shell = _ENV.shell
|
local device = _G.device
|
||||||
local term = _G.term
|
local os = _G.os
|
||||||
|
local parallel = _G.parallel
|
||||||
|
local shell = _ENV.shell
|
||||||
|
local term = _G.term
|
||||||
|
|
||||||
|
-- Example usage: mirror -r -e "vnc 1"
|
||||||
|
|
||||||
local options = {
|
local options = {
|
||||||
scale = { arg = 's', type = 'flag', value = false,
|
scale = { arg = 's', type = 'flag', value = false,
|
||||||
@@ -22,29 +27,52 @@ if not Util.getOptions(options, args) then
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local mon = _G.device[options.monitor.value]
|
local mon
|
||||||
|
for k,v in pairs(device) do
|
||||||
|
if k == options.monitor.value or v.side == options.monitor.value then
|
||||||
|
mon = v
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if not mon then
|
if not mon then
|
||||||
error('mirror: Invalid device')
|
error('mirror: Invalid device')
|
||||||
end
|
end
|
||||||
|
|
||||||
mon.clear()
|
mon.clear()
|
||||||
|
|
||||||
if options.scale.value then
|
mon.setTextScale(options.scale.value and .5 or 1)
|
||||||
mon.setTextScale(.5)
|
|
||||||
end
|
|
||||||
mon.setCursorPos(1, 1)
|
mon.setCursorPos(1, 1)
|
||||||
|
|
||||||
local oterm = Terminal.copy(term.current())
|
local oterm = term.current()
|
||||||
Terminal.mirror(term.current(), mon)
|
|
||||||
|
|
||||||
if options.resize.value then
|
if options.resize.value then
|
||||||
term.current().getSize = mon.getSize
|
oterm.reposition(1, 1, mon.getSize())
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local mirror = Terminal.mirror(term.current(), mon)
|
||||||
|
|
||||||
|
term.redirect(mirror)
|
||||||
|
|
||||||
if options.execute.value then
|
if options.execute.value then
|
||||||
-- TODO: allow args to be passed
|
parallel.waitForAny(
|
||||||
shell.run(options.execute.value) -- unpack(args))
|
function()
|
||||||
Terminal.copy(oterm, term.current())
|
shell.run(options.execute.value)
|
||||||
|
end,
|
||||||
|
|
||||||
|
function()
|
||||||
|
while true do
|
||||||
|
local event, side, x, y = os.pullEventRaw('monitor_touch')
|
||||||
|
|
||||||
|
if event == 'monitor_touch' and side == mon.side then
|
||||||
|
os.queueEvent('mouse_click', 1, x, y + 1)
|
||||||
|
os.queueEvent('mouse_up', 1, x, y + 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
)
|
||||||
|
|
||||||
|
term.redirect(oterm)
|
||||||
|
|
||||||
mon.setCursorBlink(false)
|
mon.setCursorBlink(false)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,11 +8,13 @@ local parallel = _G.parallel
|
|||||||
|
|
||||||
if not modules.launch or not modules.getMetaOwner then
|
if not modules.launch or not modules.getMetaOwner then
|
||||||
error([[Required:
|
error([[Required:
|
||||||
* kinetic augment is required')
|
* Kinetic augment
|
||||||
* error('introspection module is required]])
|
* Introspection module]])
|
||||||
end
|
end
|
||||||
|
|
||||||
local function run()
|
local function run()
|
||||||
|
local launchCounter = 0
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local meta = modules.getMetaOwner()
|
local meta = modules.getMetaOwner()
|
||||||
|
|
||||||
@@ -20,21 +22,38 @@ local function run()
|
|||||||
|
|
||||||
if meta.pitch < 0 then -- looking up
|
if meta.pitch < 0 then -- looking up
|
||||||
modules.launch(meta.yaw, meta.pitch, -meta.pitch / 22.5)
|
modules.launch(meta.yaw, meta.pitch, -meta.pitch / 22.5)
|
||||||
Sound.play('entity.bobber.throw')
|
Sound.play('entity.bobber.throw', .6)
|
||||||
|
os.sleep(0.1)
|
||||||
|
|
||||||
elseif meta.motionY < -0.5 then -- falling fast
|
elseif meta.motionY < -0.5 then -- falling fast
|
||||||
modules.launch(0, 270, 2)
|
modules.launch(0, 270, -meta.motionY + 1)
|
||||||
Sound.play('entity.bat.takeoff')
|
Sound.play('entity.bat.takeoff')
|
||||||
|
os.sleep(0)
|
||||||
|
|
||||||
|
else
|
||||||
|
os.sleep(0.1)
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif meta.isSneaking and not meta.isElytraFlying and meta.pitch == -90 then
|
||||||
|
if launchCounter < 2 then
|
||||||
|
launchCounter = launchCounter + 1
|
||||||
|
Sound.play('block.note.pling', .5)
|
||||||
|
os.sleep(0.5)
|
||||||
|
|
||||||
|
else
|
||||||
|
Sound.play('entity.bobber.throw', 1)
|
||||||
|
modules.launch(0, 270, 4)
|
||||||
|
os.sleep(0.2)
|
||||||
end
|
end
|
||||||
os.sleep(0.1)
|
|
||||||
|
|
||||||
elseif not meta.isSneaking and meta.motionY < -0.8 then
|
elseif not meta.isSneaking and meta.motionY < -0.8 then
|
||||||
print('falling...')
|
print('falling...')
|
||||||
modules.launch(0, 270, 2)
|
modules.launch(0, 270, -meta.motionY + 1)
|
||||||
Sound.play('entity.bat.takeoff')
|
Sound.play('entity.bat.takeoff')
|
||||||
os.sleep(0.1)
|
os.sleep(0)
|
||||||
|
|
||||||
else
|
else
|
||||||
|
launchCounter = 0
|
||||||
os.sleep(0.4)
|
os.sleep(0.4)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -42,14 +61,17 @@ end
|
|||||||
|
|
||||||
parallel.waitForAny(
|
parallel.waitForAny(
|
||||||
function()
|
function()
|
||||||
print('press any key to exit')
|
print('\nFlight control initialized')
|
||||||
|
print('\nSneak and look straight up for launch')
|
||||||
|
print('\nPress any key to exit')
|
||||||
os.pullEvent('char')
|
os.pullEvent('char')
|
||||||
end,
|
end,
|
||||||
function()
|
function()
|
||||||
while true do
|
while true do
|
||||||
print('Starting')
|
local _, m = pcall(run)
|
||||||
local s, m = pcall(run)
|
if m then
|
||||||
print(m)
|
print(m)
|
||||||
|
end
|
||||||
print('Waiting for 5 seconds before restarting')
|
print('Waiting for 5 seconds before restarting')
|
||||||
os.sleep(5)
|
os.sleep(5)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,10 +9,10 @@
|
|||||||
category = "Neural",
|
category = "Neural",
|
||||||
run = "neuralFight.lua",
|
run = "neuralFight.lua",
|
||||||
},
|
},
|
||||||
[ "neuralFly" ] = {
|
[ "elytraFly" ] = {
|
||||||
title = "Fly",
|
title = "ElytraFly",
|
||||||
category = "Neural",
|
category = "Neural",
|
||||||
run = "neuralFly.lua",
|
run = "elytraFly.lua",
|
||||||
},
|
},
|
||||||
[ "neuralRemote" ] = {
|
[ "neuralRemote" ] = {
|
||||||
title = "Remote",
|
title = "Remote",
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
local class = require('class')
|
||||||
local Event = require('event')
|
local Event = require('event')
|
||||||
local Socket = require('socket')
|
local Socket = require('socket')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
@@ -26,17 +27,19 @@ local function hijackTurtle(remoteId)
|
|||||||
|
|
||||||
return hijack, socket
|
return hijack, socket
|
||||||
end
|
end
|
||||||
local class = require('class')
|
|
||||||
local Swarm = class()
|
local Swarm = class()
|
||||||
function Swarm:init(args)
|
function Swarm:init(args)
|
||||||
self.pool = { }
|
self.pool = { }
|
||||||
Util.merge(self, args)
|
Util.merge(self, args)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Swarm:add(id, args)
|
function Swarm:add(id, args)
|
||||||
local member = Util.shallowCopy(args)
|
local member = Util.shallowCopy(args)
|
||||||
member.id = id
|
member.id = id
|
||||||
self.pool[id] = member
|
self.pool[id] = member
|
||||||
end
|
end
|
||||||
|
|
||||||
function Swarm:run(fn)
|
function Swarm:run(fn)
|
||||||
for id, member in pairs(self.pool) do
|
for id, member in pairs(self.pool) do
|
||||||
Event.addRoutine(function()
|
Event.addRoutine(function()
|
||||||
@@ -54,6 +57,7 @@ function Swarm:run(fn)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Swarm:shutdown()
|
function Swarm:shutdown()
|
||||||
for _, member in pairs(self.pool) do
|
for _, member in pairs(self.pool) do
|
||||||
if member.socket then
|
if member.socket then
|
||||||
@@ -62,6 +66,8 @@ function Swarm:shutdown()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Override
|
||||||
function Swarm:onRemove(member, success, msg)
|
function Swarm:onRemove(member, success, msg)
|
||||||
print('removed from pool: ' .. member.id)
|
print('removed from pool: ' .. member.id)
|
||||||
if not success then
|
if not success then
|
||||||
|
|||||||
Reference in New Issue
Block a user