forked from NeroOneTrueKing/GTNH-Power
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathredstone-control.lua
76 lines (67 loc) · 1.57 KB
/
redstone-control.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
local component = require("component")
local cfg = require("config")
function init()
if cfg.RedstoneEnabled then
assert(next(component.list("redstone")), "ERROR: Redstone enabled in config, but no redstone component!");
toggleRS = component.redstone
toggleRS.setWakeThreshold(1)
status = {[0]=false,false,false,false,false,false}
statuscnt = 0
statusmax = 0
for k,v in pairs(cfg.sidegenON) do
statusmax = statusmax + 1
end
off()
end
end
function on(side)
if not status[side] then
status[side] = true
statuscnt = statuscnt + 1
toggleRS.setOutput({[side]=15})
end
end
function off(side)
if side == nil then
status = {[0]=false,false,false,false,false,false}
toggleRS.setOutput({[0]=0,0,0,0,0,0})
elseif status[side] then
status[side] = false
statuscnt = statuscnt - 1
toggleRS.setOutput({[side]=0})
end
end
function getstatus()
return statuscnt .. "/" .. statusmax
end
function toggle(percentenergy)
for k,v in pairs(cfg.sidegenON) do
if percentenergy <= v then
on(k)
end
end
for k,v in pairs(cfg.sidegenOFF) do
if percentenergy >= v then
off(k)
end
end
end
function nullfunc() end
function nullstatus() return "RS Disabledddd" end
if cfg.RedstoneEnabled then
return {
init = init,
on = on,
off = off,
getstatus = getstatus,
toggle = toggle
}
else
return {
init = nullfunc,
on = nullfunc,
off = nullfunc,
getstatus = nullstatus,
toggle = nullfunc
}
end