diff --git a/mods/CORE/mcl_worlds/init.lua b/mods/CORE/mcl_worlds/init.lua index 4f8914506..7feab7317 100644 --- a/mods/CORE/mcl_worlds/init.lua +++ b/mods/CORE/mcl_worlds/init.lua @@ -118,11 +118,10 @@ local last_dimension = {} -- * player: Player who changed the dimension -- * dimension: New dimension ("overworld", "nether", "end", "void") function mcl_worlds.dimension_change(player, dimension) - local playername = player:get_player_name() for i=1, #mcl_worlds.registered_on_dimension_change do - mcl_worlds.registered_on_dimension_change[i](player, dimension, last_dimension[playername]) + mcl_worlds.registered_on_dimension_change[i](player, dimension, last_dimension[player]) end - last_dimension[playername] = dimension + last_dimension[player] = dimension end local dimension_change = mcl_worlds.dimension_change @@ -134,19 +133,21 @@ local DIM_UPDATE = 1 local dimtimer = 0 minetest.register_on_joinplayer(function(player) - last_dimension[player:get_player_name()] = pos_to_dimension(player:get_pos()) + last_dimension[player] = pos_to_dimension(player:get_pos()) +end) + +minetest.regsister_on_leaveplayer(function(player) + last_dimension[player] = nil end) minetest.register_globalstep(function(dtime) -- regular updates based on iterval - dimtimer = dimtimer + dtime; + dimtimer = dimtimer + dtime if dimtimer >= DIM_UPDATE then - local players = get_connected_players() - for p = 1, #players do - local dim = pos_to_dimension(players[p]:get_pos()) - local name = players[p]:get_player_name() - if dim ~= last_dimension[name] then - dimension_change(players[p], dim) + for _, player in pairs(get_connected_players()) do + local dim = pos_to_dimension(player:get_pos()) + if dim ~= last_dimension[player] then + dimension_change(player, dim) end end dimtimer = 0