skybox.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --[[
  2. # Skybox Effect
  3. Use this effect to modify a player's sky, clouds, sun, moon, or stars
  4. Expects a table as the parameter containing the following values:
  5. - ``sky_data <table>`` (optional): Sky paramaters to be applied using player.set_sky
  6. - ``cloud_data <table>`` (optional): Cloud paramaters to be applied using player.set_clouds
  7. - ``sun_data <table>`` (optional): Sun paramaters to be applied using player.set_sun
  8. - ``moon_data <table>`` (optional): Sky paramaters to be applied using player.set_moon
  9. - ``star_data <table>`` (optional): Sky paramaters to be applied using player.set_stars
  10. - ``priority <number>`` (optional): A skybox with higher priority will override lower rated ones (defaults to 1)
  11. ]]
  12. if not climate_mod.settings.skybox then return end
  13. local EFFECT_NAME = "climate_api:skybox"
  14. local function handle_effect(player_data, prev_data)
  15. for playername, data in pairs(prev_data) do
  16. for weather, _ in pairs(data) do
  17. if player_data[playername] == nil or player_data[playername][weather] == nil then
  18. climate_api.skybox.remove(playername, weather)
  19. end
  20. end
  21. end
  22. for playername, data in pairs(player_data) do
  23. for weather, value in pairs(data) do
  24. climate_api.skybox.add(playername, weather, value)
  25. end
  26. climate_api.skybox.update(playername)
  27. end
  28. end
  29. local function remove_effect(player_data)
  30. for playername, data in pairs(player_data) do
  31. for weather, _ in pairs(data) do
  32. climate_api.skybox.remove(playername, weather)
  33. end
  34. climate_api.skybox.update(playername)
  35. end
  36. end
  37. climate_api.register_effect(EFFECT_NAME, handle_effect, "tick")
  38. climate_api.register_effect(EFFECT_NAME, remove_effect, "stop")