hyperlane.lua
by hugeblank
1
local args = {...}
2
3
local mods = {}
4
local ms = peripheral.getMethods("back")
5
for i = 1, #ms do
6
mods[ms[i]] = true
7
end
8
assert(mods.getMetaOwner, "Entity Sensor & Introspection Module Required")
9
-- local can = assert(mods.canvas, "Overlay Glasses Required")()
10
assert(mods.launch, "Kinetic Augment Required.")
11
-- local sx, sy = can.getSize()
12
13
if not mods.getBlockMeta then print("No block scanner. Automatic mode unavalible.") end
14
15
16
local yaw
17
local manLaunch
18
local autoMode
19
local autoLaunch
20
21
local function meta()
22
while true do
23
local meta = peripheral.call("back", "getMetaOwner")
24
yaw = meta.yaw
25
end
26
end
27
28
29
30
local function test()
31
print("Press g to toggle manual mode.")
32
if mods.getBlockMeta then
33
print("Press a to toggle automatic mode.")
34
if args[1] then autoMode = true print("Automatic Lauch mode: ",autoMode) end
35
end
36
while true do
37
local _, char = os.pullEvent("char")
38
if char == "g" then
39
manLaunch = not manLaunch
40
autoLaunch = false
41
print("Manual Lauch mode: ",manLaunch)
42
elseif mods.getBlockMeta and char == "a" then
43
autoMode = not autoMode
44
if not autoMode then autoLaunch = false end
45
print("Automatic Lauch mode: ",autoMode)
46
end
47
end
48
end
49
50
51
52
local function autoOn()
53
while true do
54
if autoMode and not manLaunch then
55
if peripheral.call("back", "getBlockMeta", 0, -2, 0).name:match("slab") and peripheral.call("back", "getBlockMeta", 0, -3, 0).name == "minecraft:packed_ice" then
56
autoLaunch = true
57
else
58
autoLaunch = false
59
end
60
end
61
sleep(1)
62
end
63
end
64
65
66
67
local function cardinal(angle)
68
local val = math.floor((angle/90) + 0.5)
69
return 90*val
70
end
71
72
73
74
local function launch()
75
while true do
76
if manLaunch or autoLaunch then
77
peripheral.call("back", "launch", cardinal(yaw), 0, 0.5)
78
else
79
sleep()
80
end
81
end
82
end
83
local ok, err = pcall(function()
84
parallel.waitForAny(meta, test, launch, autoOn)
85
end)
86
if not ok and err ~= "Terminated" then
87
os.reboot()
88
end