mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-12-01 23:11:11 +01:00
Update sky instant if teleport between dimensions
This commit is contained in:
parent
b0c87f74fe
commit
b1d15fb667
5 changed files with 60 additions and 1 deletions
|
@ -83,3 +83,54 @@ end
|
||||||
-- Takes a position (pos) and returns true if clocks are working here
|
-- Takes a position (pos) and returns true if clocks are working here
|
||||||
mcl_worlds.clock_works = mcl_worlds.compass_works
|
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)
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ mcl_weather.skycolor = {
|
||||||
force_update = true,
|
force_update = true,
|
||||||
|
|
||||||
-- Update interval.
|
-- Update interval.
|
||||||
update_interval = 0.5,
|
update_interval = 15,
|
||||||
|
|
||||||
-- Main sky colors: starts from midnight to midnight.
|
-- Main sky colors: starts from midnight to midnight.
|
||||||
-- Please do not set directly. Use add_layer instead.
|
-- Please do not set directly. Use add_layer instead.
|
||||||
|
@ -240,3 +240,7 @@ end
|
||||||
|
|
||||||
minetest.register_on_joinplayer(initsky)
|
minetest.register_on_joinplayer(initsky)
|
||||||
minetest.register_on_respawnplayer(initsky)
|
minetest.register_on_respawnplayer(initsky)
|
||||||
|
|
||||||
|
mcl_worlds.register_on_dimension_change(function(player)
|
||||||
|
mcl_weather.skycolor.update_sky_color({player})
|
||||||
|
end)
|
||||||
|
|
|
@ -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
|
if weather_allow_abm ~= nil and weather_allow_abm == false then
|
||||||
mcl_weather.allow_abm = false
|
mcl_weather.allow_abm = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -267,6 +267,7 @@ minetest.register_abm({
|
||||||
if dim ~= "end" then
|
if dim ~= "end" then
|
||||||
obj:set_look_horizontal(math.pi/2)
|
obj:set_look_horizontal(math.pi/2)
|
||||||
end
|
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})
|
minetest.sound_play("mcl_portals_teleport", {pos=target, gain=0.5, max_hear_distance = 16})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -434,6 +434,7 @@ minetest.register_abm({
|
||||||
|
|
||||||
-- Teleport
|
-- Teleport
|
||||||
obj:set_pos(target)
|
obj:set_pos(target)
|
||||||
|
mcl_worlds.dimension_change(obj, mcl_worlds.pos_to_dimension(target))
|
||||||
if obj:is_player() then
|
if obj:is_player() then
|
||||||
minetest.sound_play("mcl_portals_teleport", {pos=target, gain=0.5, max_hear_distance = 16})
|
minetest.sound_play("mcl_portals_teleport", {pos=target, gain=0.5, max_hear_distance = 16})
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue