-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadOpenBlocksTank.lua
More file actions
65 lines (57 loc) · 1.94 KB
/
ReadOpenBlocksTank.lua
File metadata and controls
65 lines (57 loc) · 1.94 KB
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
local component = require("component")
local term = require("term")
local tankCapacity = 16000
function progressbar(percentageValue)
local fullChar = "▓"
local emptyChar = "░"
local buildingString = ""
for i = 1, 20 do
if percentageValue >= 5 then
buildingString = buildingString .. fullChar
else
buildingString = buildingString .. emptyChar
end
percentageValue = percentageValue - 5
end
return buildingString
end
function percentage(value, maxValue)
return (value / maxValue) * 100
end
function readable(number)
local str_n = tostring(number)
local formatted_n = ""
local count = 0
for i = str_n:len(), 1, -1 do
count = count + 1
formatted_n = str_n:sub(i, i) .. formatted_n
if count % 3 == 0 and i > 1 then
formatted_n = "'" .. formatted_n
end
end
return formatted_n
end
print("Enter the direction from where the redstone signal should be read.\nbottom=0\ntop=1\nback=2\nfront=3\nright=4\nleft=5\n(1,2,3,4,5): ")
local side = tonumber(term.read())
print("Enter the with of your tank:")
local width = tonumber(term.read())
print("Enter the lenght of your tank:")
local length = tonumber(term.read())
print("Enter the height of your tank:")
local height = tonumber(term.read())
if component.isAvailable("redstone") then
local redstone = component.redstone
while (true) do
local signalStrength = redstone.getInput(side)
local totalCapacityUsed = signalStrength * width * length
local totalCapacity = tankCapacity * width * length * height
term.clear()
print(readable(string.format("%.0f", totalCapacityUsed)) .. "/" .. readable(totalCapacity))
local prtg = percentage(totalCapacityUsed, totalCapacity)
print(progressbar(prtg))
print(string.format("%.2f", prtg) .. "%")
os.sleep(1)
end
else
print("No redstone component found.")
end