api.lua 751 B

1234567891011121314151617181920212223242526272829303132
  1. local CYCLE = 8 -- Time period of cyclic clouds update in seconds
  2. weather = {}
  3. -- default implementation is empty
  4. function weather.get(player)
  5. return {}
  6. end
  7. local function do_update()
  8. for _, player in ipairs(minetest.get_connected_players()) do
  9. local params = weather.get(player)
  10. assert(params ~= nil, "weather.get() must not return nil")
  11. if params.clouds then
  12. player:set_clouds(params.clouds)
  13. end
  14. if params.lighting then
  15. player:set_lighting(params.lighting)
  16. end
  17. end
  18. end
  19. local function cyclic_update()
  20. do_update()
  21. minetest.after(CYCLE, cyclic_update)
  22. end
  23. minetest.after(0, cyclic_update)
  24. -- Update on player join to instantly alter clouds from the default
  25. minetest.register_on_joinplayer(function(player)
  26. do_update()
  27. end)