trainworld_computercraft/computer/15/dirt.lua
2025-07-03 19:37:25 +02:00

85 lines
2 KiB
Lua

basin = peripheral.wrap("top")
base_item = "dirt"
levels = {
compressed = 1,
double_compressed = 2,
triple_compressed = 3,
quadruple_compressed = 4,
quintuple_compressed = 5,
sextuple_compressed = 6,
septuple_compressed = 7,
octuple_compressed = 8,
}
unpacked = {
9,
81,
729,
6561,
59049,
531441,
4782969,
43046721
}
startup_total = nil
startup_time = os.epoch("utc")
speed = 0
function format_time(seconds)
local t = math.floor(seconds)
local t_s = t % 60
local t_m = math.floor(t / 60) % 60
local t_h = math.floor(t / 3600) % 24
local t_d = math.floor(t / 86400)
function two_digit(n)
return n<10 and "0"..tostring(n) or tostring(n)
end
return t_d.."d "..two_digit(t_h)..":"..two_digit(t_m)..":"..two_digit(t_s)
end
function update()
local counts = {}
local raw = basin.list()
local total = 0
for _, item in pairs(raw) do
name = string.sub(item.name, string.len("compressor:_"), -string.len(base_item)-2)
count = item.count
if levels[name] then
counts[levels[name]] = count
total = total + unpacked[levels[name]] * count
end
end
local time = os.epoch("utc")
if not startup_total then
startup_total = total
end
speed = math.floor((total - startup_total) / ((time - startup_time) / 1000) * 100) / 100
-- draw
term.clear()
term.setCursorPos(1,1)
print(base_item, "progress")
for level = 1, 7 do
local count = counts[level] or 0
local bar = string.rep("#", count) .. string.rep(".", 9 - count)
print("lvl", level, bar)
end
print()
print("total: ", total)
local progress = total / unpacked[8] * 100
print(string.format("octuple: %.5f%%\n", progress))
print("speed:", speed, base_item .. "/s")
local eta = math.floor((unpacked[8] - progress) / speed + 0.5)
print("uptime:", format_time((time - startup_time) / 1000))
print("remaining:", format_time(eta))
end
while true do
update()
sleep(2)
end