minetest-mods / 3d_armor

Visible player armor & wielded items for minetest
Other
17 stars 39 forks source link

"Armor not initialized!" when 3d_armor is part of a game #114

Closed dacmot closed 1 year ago

dacmot commented 1 year ago

Hi. I'm one of the WhyNot? game maintainers and we've noticed a problem with 3d_armor recently (https://github.com/minetest-whynot/whynot-game/issues/169)

The first player to immediately join a new game (first time only, singleplayer or hosted), the armor tab in the inventory says "Armor not initialized!" Quitting and joining again fixes it, but it's still annoying.

This it not specific to WhyNot. I was able to reproduce it by copying 3d_armor into minetest_game/mods, as well as simply enabling 3d_armor on a new MTG world before joining.

I've tracked it down to the init_player_armor function at

    armor.def[name] = {
        init_time = minetest.get_gametime(),

Where minetest.get_gametime() is probably 0 when you first join a new world.

I found a quick workaround by using minetest.after(1 in init.lua:

minetest.register_on_joinplayer(function(player)
    default.player_set_model(player, "3d_armor_character.b3d")
    local player_name = player:get_player_name()

    minetest.after(0, function()
        -- TODO: Added in 7566ecc - What's the prupose?
        local pplayer = minetest.get_player_by_name(player_name)
        if pplayer and init_player_armor(pplayer) == false then
            pending_players[pplayer] = 0
        end
    end)
end)

but given the TODO comment, I thought maybe this needs some deeper investigation.

BuckarooBanzay commented 1 year ago

thanks for reporting that :+1:

i tried to clean up that mess a bit in https://github.com/minetest-mods/3d_armor/pull/115 let me know if that works for you

dacmot commented 1 year ago

I'll take a look. Thanks!

dacmot commented 1 year ago

As mentioned in the PR, it looks good!

Niklp09 commented 1 year ago

Should not happen anymore since the code was removed in https://github.com/minetest-mods/3d_armor/commit/3660e503122b75c77edc0f048320a11e8dccc174. As always, re-open if needed.