Remove crash on creative to survival gamemode change

This commit is contained in:
kay27 2022-02-19 03:03:23 +04:00
parent 9f395390e4
commit 7c5554a0f6
2 changed files with 27 additions and 22 deletions

View File

@ -52,11 +52,11 @@ end
-- Load default settings
dofile(modpath.."/default_settings.lua")
if minetest.get_modpath("mcl_experience") and not minetest.is_creative_enabled("") then
--if minetest.get_modpath("mcl_experience") and not minetest.is_creative_enabled("") then
-- reserve some space for experience bar:
hb.settings.start_offset_left.y = hb.settings.start_offset_left.y - 20
hb.settings.start_offset_right.y = hb.settings.start_offset_right.y - 20
end
--end
local function player_exists(player)
return player ~= nil and player:is_player()

View File

@ -156,6 +156,27 @@ function mcl_experience.throw_xp(pos, total_xp)
end
end
local function init_hudbars(player)
if not minetest.is_creative_enabled(player:get_player_name()) then
hud_bars[player] = player:hud_add({
hud_elem_type = "image",
position = {x = 0.5, y = 1},
offset = {x = (-9 * 28) - 3, y = -(48 + 24 + 16 - 5)},
scale = {x = 2.8, y = 3.0},
alignment = {x = 1, y = 1},
z_index = 11,
})
hud_levels[player] = player:hud_add({
hud_elem_type = "text",
position = {x = 0.5, y = 1},
number = 0x80FF20,
offset = {x = 0, y = -(48 + 24 + 24)},
z_index = 12,
})
end
end
function mcl_experience.update(player)
if not mcl_util or not mcl_util.is_player(player) then return end
local xp = mcl_experience.get_xp(player)
@ -164,6 +185,9 @@ function mcl_experience.update(player)
cache.level = xp_to_level(xp)
if not minetest.is_creative_enabled(player:get_player_name()) then
if not hud_bars[player] then
init_hudbars(player)
end
player:hud_change(hud_bars[player], "text", "mcl_experience_bar_background.png^[lowpart:"
.. math.floor(math.floor(xp_to_bar(xp, cache.level) * 18) / 18 * 100)
.. ":mcl_experience_bar.png^[transformR270"
@ -187,26 +211,7 @@ minetest.register_on_joinplayer(function(player)
caches[player] = {
last_time = get_time(),
}
if not minetest.is_creative_enabled(player:get_player_name()) then
hud_bars[player] = player:hud_add({
hud_elem_type = "image",
position = {x = 0.5, y = 1},
offset = {x = (-9 * 28) - 3, y = -(48 + 24 + 16 - 5)},
scale = {x = 2.8, y = 3.0},
alignment = {x = 1, y = 1},
z_index = 11,
})
hud_levels[player] = player:hud_add({
hud_elem_type = "text",
position = {x = 0.5, y = 1},
number = 0x80FF20,
offset = {x = 0, y = -(48 + 24 + 24)},
z_index = 12,
})
end
init_hudbars(player)
mcl_experience.update(player)
end)