Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Full script updated to strip mod names from fluid labels
- local tanks = {
- {
- amount = 5000,
- capacity = 10000,
- fluid = "mod:water"
- },
- {
- amount = 2500,
- capacity = 5000,
- fluid = "mod:submod:lava",
- color = "red"
- },
- }
- local function renderTank(x, y, widthPercent, heightPercent, tank)
- local w, h = term.getSize()
- local width = math.max(1, math.floor(w * widthPercent))
- local height = math.max(1, math.floor(h * heightPercent))
- local fillRatio = tank.amount / tank.capacity
- local filledHeight = math.floor(height * fillRatio)
- local fluidColorMap = {
- ["blue"] = colors.blue,
- ["red"] = colors.red,
- default = colors.green
- }
- local fillColor = fluidColorMap[tank.color] or fluidColorMap.default
- -- Extract only the last part of the fluid name after the last colon
- local label = tank.fluid:match("([^:]+)$")
- local labelWidth = #label
- local centeredX = x + math.floor((labelWidth - width) / 2)
- for i = 1, height do
- term.setCursorPos(centeredX, y + height - i)
- if i <= filledHeight then
- term.setBackgroundColor(fillColor)
- else
- term.setBackgroundColor(colors.gray)
- end
- term.write(string.rep(" ", width))
- end
- -- Draw fill percent inside bar at top of filled section, centered
- if filledHeight > 0 then
- local percentText = string.format("%d%%", fillRatio * 100)
- local textX = centeredX + math.floor((width - #percentText) / 2)
- term.setCursorPos(textX, y + height - filledHeight)
- term.setBackgroundColor(fillColor)
- term.setTextColor(colors.white)
- term.write(percentText)
- term.setTextColor(colors.white)
- end
- term.setBackgroundColor(colors.black)
- -- Print fluid name below
- term.setCursorPos(x, y + height + 1)
- term.write(label)
- end
- term.clear()
- renderTank(4, 2, 0.1, 0.8, tanks[1])
- renderTank(25, 2, 0.1, 0.8, tanks[2])
- -- Let me know next enhancements or auto-refresh loop requirements.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement