Advertisement
xX-AAAAAAAAAA-Xx

ComputerCraft Clock (NOT MINE)

Aug 16th, 2024
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | Source Code | 0 0
  1. -- Clock with Date for display on a monitor
  2. -- Author: CecilKilmer (modified by ChatGPT)
  3. -- Version: 1.1
  4. -- Date: 2023/08/16
  5.  
  6. -- Min width required (IE: 10:00 PM)
  7. minWidthReq = 12
  8. minHeightReq = 4
  9.  
  10. -- Figure out where our monitor is
  11. monitorSide = nil
  12. monitor = nil
  13.  
  14. if peripheral.getType("left") == "monitor" then
  15. monitorSide = "left"
  16. elseif peripheral.getType("right") == "monitor" then
  17. monitorSide = "right"
  18. elseif peripheral.getType("top") == "monitor" then
  19. monitorSide = "top"
  20. elseif peripheral.getType("bottom") == "monitor" then
  21. monitorSide = "bottom"
  22. elseif peripheral.getType("front") == "monitor" then
  23. monitorSide = "front"
  24. elseif peripheral.getType("back") == "monitor" then
  25. monitorSide = "back"
  26. end
  27.  
  28. screenWidth = 0
  29. screenHeight = 0
  30.  
  31. -- If we have one, redirect term to it
  32. if monitorSide ~= nil then
  33. monitor = peripheral.wrap(monitorSide)
  34. term.redirect(monitor)
  35.  
  36. local scale = 5.5
  37.  
  38. repeat
  39. scale = scale - 0.5
  40. monitor.setTextScale(scale)
  41. screenWidth, screenHeight = term.getSize()
  42. until screenWidth > minWidthReq and screenHeight > minHeightReq
  43. end
  44.  
  45. -- Determine our screen size
  46. screenWidth, screenHeight = term.getSize()
  47. yPos = screenHeight - minHeightReq
  48. yPos = math.floor(yPos / 2)
  49.  
  50. -- Helper functions for Minecraft time conversion
  51. function getMinecraftDateTime()
  52. local time = os.time()
  53.  
  54. -- Minecraft day count (assuming each day is 24000 ticks)
  55. local day = math.floor(time / 24000) + 1
  56.  
  57. -- Extract year, month, and day
  58. local year = math.floor(day / 360) + 1 -- assuming 360 days per year
  59. local month = math.floor((day % 360) / 30) + 1 -- assuming 30 days per month
  60. local dayOfMonth = (day % 360) % 30 + 1
  61.  
  62. -- Format time and date
  63. local formattedTime = textutils.formatTime(time, false)
  64. local formattedDate = string.format("Day %02d, Month %02d, Year %d", dayOfMonth, month, year)
  65.  
  66. return formattedTime, formattedDate
  67. end
  68.  
  69. -- Main loop
  70. while true do
  71. term.clear()
  72.  
  73. local formattedTime, formattedDate = getMinecraftDateTime()
  74.  
  75. local xPosTime = screenWidth - string.len(formattedTime)
  76. xPosTime = math.ceil(xPosTime / 2)
  77. term.setCursorPos(xPosTime + 1, yPos + 2)
  78. print(formattedTime)
  79.  
  80. local xPosDate = screenWidth - string.len(formattedDate)
  81. xPosDate = math.ceil(xPosDate / 2)
  82. term.setCursorPos(xPosDate + 1, yPos + 1)
  83. print(formattedDate)
  84.  
  85. sleep(.1)
  86. end
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement