-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGregtech&Reactor.lua
130 lines (119 loc) · 3.02 KB
/
Gregtech&Reactor.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
component = require("component")
rs = component.redstone
gpu = component.gpu
sides = require("sides")
event = require("event")
b = component.gt_batterybuffer
i = 1
totalbatteries = 0
nilcheck = b.getBatteryCharge(0)
gpu.setResolution(40, 12)
local w, h = gpu.getResolution()
local energy = 0
local menergy = 0
local percent = 0
local run = false
local energyUsage = 0
local plus = false
function touchHandler(_, _, x, y)
if x >= w/2 - 7 then
if x <= w/2 + 7 then
if y >= 9 then
if y <= 11 then
if run then
run = false
else
run = true
end
updateScreen()
end
end
end
end
end
event.listen("touch", touchHandler)
local function updateScreen()
gpu.setBackground(0x000000)
gpu.fill(1, 1, w, h, " ")
gpu.setForeground(0xFFFF00)
gpu.set(w/2 - 15, 1, "==Reactor&Battery Controller==")
str = energy .. "EU / " .. menergy .. "EU"
gpu.setForeground(0x00FF00)
gpu.set(w/2 - string.len(str) / 2, 3, str)
if plus then
str = "+ " .. energyUsage
gpu.setForeground(0x0000FF)
else
str = "- " .. energyUsage
gpu.setForeground(0xFF00FF)
end
gpu.set(w/2 - string.len(str) / 2, 4, str)
gpu.setForeground(0xFF0000)
gpu.set(w/2 - 15, 5, "¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦")
numQuad = math.floor(((percent / 100) * 30) + 0.5)
gpu.fill(w/2 - 15, 5, numQuad, 1, "¦")
gpu.setForeground(0x00FF00)
gpu.set(w/2 - 2, 6, percent .. "%")
gpu.set(w/2 - 7, 8, "Reactor Status")
if run then
gpu.setForeground(0x00FF00)
gpu.fill(w/2 - 7, 9, 14, 3, "¦")
gpu.setForeground(0xFFFFFF)
gpu.setBackground(0x00FF00)
gpu.set(w/2 - 2, 10, "ON")
else
gpu.setForeground(0xFF0000)
gpu.fill(w/2 - 7, 9, 14, 3, "¦")
gpu.setForeground(0xFFFFFF)
gpu.setBackground(0xFF0000)
gpu.set(w/2 - 2, 10, "OFF")
end
gpu.setForeground(0x000000)
end
while nilcheck ~= b.getBatteryCharge(i) do
totalbatteries = totalbatteries + 1
i = i + 1
end
savedenergy = 0
while true do
i = 1
energy = 0
menergy = 0
while i <= totalbatteries do
energy = energy + b.getBatteryCharge(i)
menergy = menergy + b.getMaxBatteryCharge(i)
i = i + 1
end
energy = energy + b.getEUStored()
if savedenergy == 0 then
savedenergy = energy
end
menergy = menergy + b.getEUMaxStored()
percent = math.floor(((energy / menergy) * 100) + 0.5)
if savedenergy > energy then
energyUsage = savedenergy - energy
energyUsage = energyUsage / 20
plus = false
elseif savedenergy < energy then
energyUsage = energy - savedenergy
energyUsage = energyUsage / 20
plus = true
elseif savedenergy == energy then
energyUsage = 0
plus = true
end
if percent < 10 then
run = true
end
if percent > 80 then
run = false
end
savedenergy = energy
if run then
rs.setOutput(sides.right, 15)
else
rs.setOutput(sides.right, 0)
end
updateScreen()
os.sleep(1)
end