mcl_worlds: Use player refs for indexing

This commit is contained in:
Lizzy Fleckenstein 2022-05-26 13:15:50 +02:00
parent 2156ec2793
commit f87512a5e4
Signed by: LizzyFleckenstein03
GPG Key ID: 06927A5199D6C9B2
1 changed files with 12 additions and 11 deletions

View File

@ -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