Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Clock for display on a monitor
- -- Author: CecilKilmer
- -- Version: 2.0
- -- Date: 2024/08/16
- -- Min width required (IE: 10:00 PM + Date)
- minWidthReq = 10
- minHeightReq = 4
- -- Figure out where our monitor is
- monitorSide = nil
- monitor = nil
- if peripheral.getType("left") == "monitor" then
- monitorSide = "left"
- elseif peripheral.getType("right") == "monitor" then
- monitorSide = "right"
- elseif peripheral.getType("top") == "monitor" then
- monitorSide = "top"
- elseif peripheral.getType("bottom") == "monitor" then
- monitorSide = "bottom"
- elseif peripheral.getType("front") == "monitor" then
- monitorSide = "front"
- elseif peripheral.getType("back") == "monitor" then
- monitorSide = "back"
- end
- screenWidth = 0
- screenHeight = 0
- -- If we have one, redirect term to it
- if monitorSide ~= nil then
- monitor = peripheral.wrap(monitorSide)
- term.redirect(monitor)
- local scale = 5.5
- repeat
- scale = scale - 0.5
- monitor.setTextScale(scale)
- screenWidth, screenHeight = term.getSize()
- until screenWidth > minWidthReq and screenHeight > minHeightReq
- end
- -- Determine our screen size
- screenWidth, screenHeight = term.getSize()
- yPos = screenHeight - minHeightReq
- yPos = math.floor(yPos / 2)
- -- Function to convert Minecraft days to a calendar date
- function convertToCalendar(day)
- local year = math.floor(day / 360) + 1 -- Each year has 360 days (12 months * 30 days)
- local month = math.floor((day % 360) / 30) + 1 -- 30 days per month
- local dayOfMonth = (day % 30) + 1
- return dayOfMonth, month, year
- end
- -- Main loop
- while true do
- term.clear()
- -- Get current Minecraft time and day
- local time = os.time()
- local day = os.day()
- -- Format the time and date
- time = textutils.formatTime(time, false)
- local dayOfMonth, month, year = convertToCalendar(day)
- local dateString = string.format("%02d/%02d/%04d", dayOfMonth, month, year)
- -- Calculate positions
- local xPosTime = screenWidth - string.len(time)
- xPosTime = math.ceil(xPosTime / 2)
- local xPosDate = screenWidth - string.len(dateString)
- xPosDate = math.ceil(xPosDate / 2)
- -- Display time and date
- term.setCursorPos(xPosTime + 1, yPos + 1)
- print(time)
- term.setCursorPos(xPosDate + 1, yPos + 3)
- print(dateString)
- sleep(.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement