-- Open a rednet connection peripheral.find("modem", rednet.open) -- A function to make a cool terminal window function makeScreen(lines) term.clear() term.setCursorPos(1, 1) for i = 1, #lines do print(lines[i]) end print("\nCakeHUD") end -- Gets power level from the block below the computer function getPowerLevel() local block = peripheral.wrap("bottom") return { power = block.getEnergyStored(), maxPower = block.getEnergyCapacity() } end -- Gets the server's TPS function getTPS() local game_time_start = os.epoch "utc" sleep(0.1) local game_time_end = os.epoch "utc" local game_time_diff = game_time_end - game_time_start local utc_elapsed_seconds = game_time_diff / 100 return 20 / utc_elapsed_seconds end function getReactorStatus() -- wait for a message on the cakehud_reactor channel local senderId, message, protocol = rednet.receive("cakehud_reactor") -- true if the reactor is charging, false if it's discharging return message == "reactor_charging" end local todo = {} -- open the todo file if fs.exists("todo.txt") then local file = fs.open("todo.txt", "r") todo = textutils.unserialize(file.readAll()) file.close() end function waitForTodo() -- wait for a message on the cakehud_todo channel local senderId, message, protocol = rednet.receive("cakehud_todo") print("Received todo message: " .. message) -- deserialize the message local data = textutils.unserialize(message) -- add the data to the todo list if data.type == "add" then table.insert(todo, data.text) print("Added todo item: " .. data.text) end -- remove the data from the todo list if data.type == "delete" then -- find the index of the todo item if todo[data.id] then table.remove(todo, data.id) end end -- write the todo to file local file = fs.open("todo.txt", "w") file.write(textutils.serialize(todo)) file.close() end -- Main loop function processData() -- Run the functions asynchronously local powerLevel = getPowerLevel() local tps = getTPS() local reactorStatus = getReactorStatus() -- Make the screen makeScreen({ "TPS: " .. math.floor(tps), "Power: " .. powerLevel.power .. "/" .. powerLevel.maxPower, "Reactor status: " .. (reactorStatus and "charging" or "discharging") }) -- Transmit the data rednet.broadcast(textutils.serialize({ power = powerLevel, tps = tps, reactorStatus = reactorStatus, todo = todo }), "cakehud") -- Wait sleep(0.25) end -- Run the main loop while true do parallel.waitForAny(processData, waitForTodo) end