diff --git a/mods/CORE/mcl_worlds/init.lua b/mods/CORE/mcl_worlds/init.lua index 234ef5229..da5999444 100644 --- a/mods/CORE/mcl_worlds/init.lua +++ b/mods/CORE/mcl_worlds/init.lua @@ -83,3 +83,54 @@ end -- Takes a position (pos) and returns true if clocks are working here mcl_worlds.clock_works = mcl_worlds.compass_works +--------------- CALLBACKS ------------------ +mcl_worlds.registered_on_dimension_change = {} + +-- Register a callback function func(player, dimension). +-- It will be called whenever a player changes between dimensions. +-- The void counts as dimension. +-- * player: The player who changed the dimension +-- * dimension: The new dimension of the player ("overworld", "nether", "end", "void"). +function mcl_worlds.register_on_dimension_change(func) + table.insert(mcl_worlds.registered_on_dimension_change, func) +end + +-- Playername-indexed table containig the name of the last known dimension the +-- player was in. +local last_dimension = {} + +-- Notifies this mod about a dimension change of a player. +-- * player: Player who changed the dimension +function mcl_worlds.dimension_change(player, dimension) + for i=1, #mcl_worlds.registered_on_dimension_change do + mcl_worlds.registered_on_dimension_change[i](player, dimension) + last_dimension[player:get_player_name()] = dimension + end +end + +----------------------- INTERNAL STUFF ---------------------- + +-- Update the dimension callbacks every DIM_UPDATE seconds +local DIM_UPDATE = 1 +local dimtimer = 0 + +minetest.register_on_joinplayer(function(player) + last_dimension[player:get_player_name()] = mcl_worlds.pos_to_dimension(player:get_pos()) +end) + +minetest.register_globalstep(function(dtime) + -- regular updates based on iterval + dimtimer = dimtimer + dtime; + if dimtimer >= DIM_UPDATE then + local players = minetest.get_connected_players() + for p=1, #players do + local dim = mcl_worlds.pos_to_dimension(players[p]:get_pos()) + local name = players[p]:get_player_name() + if dim ~= last_dimension[name] then + mcl_worlds.dimension_change(players[p], dim) + end + end + dimtimer = 0 + end +end) + diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor.lua b/mods/ENVIRONMENT/mcl_weather/skycolor.lua index dd8185a34..ab8ab5a63 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor.lua @@ -6,7 +6,7 @@ mcl_weather.skycolor = { force_update = true, -- Update interval. - update_interval = 0.5, + update_interval = 15, -- Main sky colors: starts from midnight to midnight. -- Please do not set directly. Use add_layer instead. @@ -240,3 +240,7 @@ end minetest.register_on_joinplayer(initsky) minetest.register_on_respawnplayer(initsky) + +mcl_worlds.register_on_dimension_change(function(player) + mcl_weather.skycolor.update_sky_color({player}) +end) diff --git a/mods/ENVIRONMENT/mcl_weather/weather_core.lua b/mods/ENVIRONMENT/mcl_weather/weather_core.lua index f5a9f62eb..6fab2e25e 100644 --- a/mods/ENVIRONMENT/mcl_weather/weather_core.lua +++ b/mods/ENVIRONMENT/mcl_weather/weather_core.lua @@ -218,3 +218,5 @@ local weather_allow_abm = minetest.settings:get_bool("weather_allow_abm") if weather_allow_abm ~= nil and weather_allow_abm == false then mcl_weather.allow_abm = false end + + diff --git a/mods/ITEMS/mcl_portals/portal_end.lua b/mods/ITEMS/mcl_portals/portal_end.lua index c7638a5f9..24a58a7d4 100644 --- a/mods/ITEMS/mcl_portals/portal_end.lua +++ b/mods/ITEMS/mcl_portals/portal_end.lua @@ -267,6 +267,7 @@ minetest.register_abm({ if dim ~= "end" then obj:set_look_horizontal(math.pi/2) end + mcl_worlds.dimension_change(obj, mcl_worlds.pos_to_dimension(target)) minetest.sound_play("mcl_portals_teleport", {pos=target, gain=0.5, max_hear_distance = 16}) end end diff --git a/mods/ITEMS/mcl_portals/portal_nether.lua b/mods/ITEMS/mcl_portals/portal_nether.lua index 8b0efea6e..cd47ff8ac 100644 --- a/mods/ITEMS/mcl_portals/portal_nether.lua +++ b/mods/ITEMS/mcl_portals/portal_nether.lua @@ -434,6 +434,7 @@ minetest.register_abm({ -- Teleport obj:set_pos(target) + mcl_worlds.dimension_change(obj, mcl_worlds.pos_to_dimension(target)) if obj:is_player() then minetest.sound_play("mcl_portals_teleport", {pos=target, gain=0.5, max_hear_distance = 16}) end