Mekanism Boiler Saftyvalve
gelatine87 |
PRO |
05/25/24 06:08:20 PM UTC (Edited) |
0 ⭐ |
1120 👁️ |
Never ⏰ |
[computercraft, Mekanism, boiler]
-- Function to ensure the presence of required peripherals (monitor and teleporter).
local function checkPeripheral(name, errorMessage)
local peripheral = peripheral.find(name)
if not peripheral then
error(errorMessage)
end
return peripheral
end
-- Retrieve peripherals
local boiler = checkPeripheral("boilerValve", "Boiler peripheral not found.")
local function getThresholds(maxCap)
return maxCap * 0.9, maxCap * 0.7
end
local function drawBar(amount, maxCap)
local width, height = term.getSize()
local barLength = math.floor(width * 0.8)
local fillPercentage = amount / maxCap
local fillLength = math.floor(fillPercentage * barLength)
local upperThreshold, lowerThreshold = getThresholds(maxCap)
local upperMark = math.floor(upperThreshold / maxCap * barLength)
local lowerMark = math.floor(lowerThreshold / maxCap * barLength)
local startX = math.floor((width - barLength) / 2)
local bar = string.char(143)
term.clear()
term.setCursorPos(startX, 1)
term.write("0%")
term.setCursorPos(startX + lowerMark - 1, 1)
term.write("70%")
term.setCursorPos(startX + upperMark - 1, 1)
term.write("90%")
term.setCursorPos(startX + barLength, 1)
term.write("100%")
term.setCursorPos(startX, 2)
term.write("[")
for i = 1, barLength do
if i == upperMark then
term.setTextColor(colors.red)
term.write("|")
elseif i == lowerMark then
term.setTextColor(colors.green)
term.write("|")
elseif i <= fillLength then
if fillPercentage >= 0.9 then
term.setTextColor(colors.red) -- Füllstand über 90% -> Rot
elseif fillPercentage <= 0.7 then
term.setTextColor(colors.white) -- Füllstand unter 70% -> Grün
elseif fillPercentage >= 0.7 and fillPercentage <= 0.9 then
term.setTextColor(colors.green) -- Füllstand zwischen 70% und 90% -> Grün
else
term.setTextColor(colors.white) -- Normaler Bereich -> Weiß
end
term.write(bar)
else
term.write(" ")
end
end
term.setTextColor(colors.white)
term.write("]")
term.setCursorPos(math.floor((width - 40) / 2), 4)
print(string.format("Füllstand: %.2f%%", fillPercentage * 100))
term.setCursorPos(math.floor((width - 40) / 2), 5)
print(string.format("Sodium: %d / %d", amount, maxCap))
end
local function updateRedstone(exceedsUpper, fallsBelowLower)
local newState = exceedsUpper and 15 or (fallsBelowLower and 0 or nil)
if newState then
rs.setAnalogOutput("right", newState)
end
end
while true do
local maxCap = boiler.getHeatedCoolantCapacity()
local amount = boiler.getHeatedCoolant().amount
if type(maxCap) ~= "number" or type(amount) ~= "number" then
print("Error: maxCap oder amount sind keine Zahlen")
else
local upperThreshold, lowerThreshold = getThresholds(maxCap)
local exceedsUpper = amount >= upperThreshold
local fallsBelowLower = amount <= lowerThreshold
updateRedstone(exceedsUpper, fallsBelowLower)
drawBar(amount, maxCap)
end
sleep(1)
end
Comments