Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Clock with Date for display on a monitor
- -- Author: CecilKilmer (modified by ChatGPT)
- -- Version: 1.1
- -- Date: 2023/08/16
- -- Min width required (IE: 10:00 PM)
- minWidthReq = 12
- 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)
- -- Helper functions for Minecraft time conversion
- function getMinecraftDateTime()
- local time = os.time()
- -- Minecraft day count (assuming each day is 24000 ticks)
- local day = math.floor(time / 24000) + 1
- -- Extract year, month, and day
- local year = math.floor(day / 360) + 1 -- assuming 360 days per year
- local month = math.floor((day % 360) / 30) + 1 -- assuming 30 days per month
- local dayOfMonth = (day % 360) % 30 + 1
- -- Format time and date
- local formattedTime = textutils.formatTime(time, false)
- local formattedDate = string.format("Day %02d, Month %02d, Year %d", dayOfMonth, month, year)
- return formattedTime, formattedDate
- end
- -- Main loop
- while true do
- term.clear()
- local formattedTime, formattedDate = getMinecraftDateTime()
- local xPosTime = screenWidth - string.len(formattedTime)
- xPosTime = math.ceil(xPosTime / 2)
- term.setCursorPos(xPosTime + 1, yPos + 2)
- print(formattedTime)
- local xPosDate = screenWidth - string.len(formattedDate)
- xPosDate = math.ceil(xPosDate / 2)
- term.setCursorPos(xPosDate + 1, yPos + 1)
- print(formattedDate)
- sleep(.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement