Satscape

ComputerCraft clock and weather report

Sep 2nd, 2012
6,432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.13 KB | None | 0 0
  1. -- Computercraft Computer script by Scott 'Satscape' Hather
  2. -- this will display the current Minecraft time
  3. -- along with a weather report
  4. -- It will require a world sensor placing into your world and a sensor controller
  5. -- attaching to your computer. Optional: large monitor to display this data.
  6.  
  7. os.unloadAPI ("sensors")
  8. os.loadAPI ("/rom/apis/sensors")
  9. conside = sensors.getController() --what side is the controller on
  10. sens = sensors.getSensors(conside)
  11. weatherSensor = sens[1]       -- The first sensor (if you have more, change this)
  12. probes = sensors.getProbes(conside,weatherSensor)
  13. areaProbe = probes[2]
  14. targets = sensors.getAvailableTargetsforProbe(conside,weatherSensor,areaProbe)
  15. target=targets[1]
  16. sensors.setTarget(conside,weatherSensor,target)
  17.  
  18. m=peripheral.wrap("right")  -- monitor is to the right
  19. m.setTextScale(3)   -- scale is 1 to 5, set to 3
  20.  
  21. while true do       -- use control T to terminate this infinite loop
  22. rs.setOutput("top",true)    --Turn on redstone light above
  23. term.clear()
  24.  
  25. -- GET THE TIME STUFF
  26. mins=os.time() % 1
  27. mins=mins*60
  28. theTime=string.format("%02d:%02d", math.floor(os.time()), mins)  -- FORMAT THE TIME
  29.  
  30. if os.time() >18 then
  31. theTime2 ="Evening"
  32.  
  33. elseif os.time() >17 then
  34. theTime2 = "Sunset"
  35.  
  36. elseif os.time() >12 then
  37. theTime2 = "Afternoon"
  38.  
  39. elseif os.time() >5 then
  40. theTime2 = "Morning"
  41.  
  42. elseif os.time() >4 then
  43. theTime2 = "Sunrise"
  44.  
  45. else
  46. theTime2 = "Late night"
  47. end
  48.  
  49.  
  50. -- READ FROM PROBE
  51. reading=sensors.getSensorReadingAsDict(conside,weatherSensor,target,areaProbe)
  52. raining=reading.isRaining
  53. thunder=reading.isThunderStorm
  54.  
  55. if thunder then
  56. theWeather="Thunder"
  57.  
  58. elseif raining then
  59. theWeather="Rain"
  60.  
  61. else
  62.  if reading.isDaytime then
  63.   theWeather="Sunshine"
  64.  else
  65.   theWeather="Clear skies"
  66.  end
  67. end
  68.  
  69. -- DISPLAY EVERYTHING
  70. term.setCursorPos(1,2)
  71. print("Time");
  72. term.setCursorPos(10,2)
  73. print(theTime)
  74. term.setCursorPos(10,3)
  75. print(theTime2)
  76. term.setCursorPos(1,5)
  77. print("Weather")
  78. term.setCursorPos(10,5)
  79. print(theWeather)
  80.  
  81. sleep(10)           -- no need to hammer this script, take it easy, have a nap.
  82. rs.setOutput("top",false)   -- turn off the redstone light
  83. sleep(1)
  84. end
Advertisement
Add Comment
Please, Sign In to add comment