Fix "hud_elem_type" deprecation warning spam (5.9+) ()

`mcl_vars.hud_type_field` is introduced to determine the right HUD element type field to use. All mods adding HUDs, together with their `mod.conf` files, are changed accordingly to silence the warnings.

Reviewed-on: https://git.minetest.land/VoxeLibre/VoxeLibre/pulls/4965
Reviewed-by: teknomunk <teknomunk@protonmail.com>
Co-authored-by: Mikita Wiśniewski <rudzik8@protonmail.com>
Co-committed-by: Mikita Wiśniewski <rudzik8@protonmail.com>
This commit is contained in:
Mikita Wiśniewski 2025-03-04 20:50:10 +01:00 committed by the-real-herowl
parent 9a6d5d68c8
commit ef0d38e530
35 changed files with 75 additions and 61 deletions
mods
CORE/mcl_init
ENTITIES/mcl_burning
HUD
awards
hudbars
mcl_bossbars
mcl_credits
mcl_experience
mcl_info
mcl_offhand
mcl_title
show_wielded_item
ITEMS
PLAYER/mcl_hunger

View file

@ -45,6 +45,9 @@ mcl_vars.gui_nonbg = table.concat({
mcl_vars.gui_bg_color = "bgcolor[#00000000]"
mcl_vars.gui_bg_img = "background9[1,1;1,1;mcl_base_textures_background9.png;true;7]"
-- HUD element type field, stored separately to avoid deprecation warnings (5.9+)
mcl_vars.hud_type_field = core.features["hud_def_type_field"] and "type" or "hud_elem_type"
-- Tool wield size
mcl_vars.tool_wield_scale = vector.new(1.8, 1.8, 1)

View file

@ -56,6 +56,8 @@ function mcl_burning.get_touching_nodes(obj, nodenames, storage)
return nodes
end
local hud_type_field = mcl_vars.hud_type_field
-- Manages the fire animation on a burning player's HUD
--
-- Parameters:
@ -72,7 +74,7 @@ function mcl_burning.update_hud(player)
if not storage.fire_hud_id then
storage.animation_frame = 1
storage.fire_hud_id = player:hud_add({
hud_elem_type = "image",
[hud_type_field] = "image",
position = {x = 0.5, y = 0.5},
scale = {x = -100, y = -100},
text = hud_flame_animated .. storage.animation_frame,

View file

@ -1,4 +1,4 @@
name = mcl_burning
description = Burning Objects for VoxeLibre
author = Fleckenstein
depends = mcl_weather, mcl_worlds
depends = mcl_weather, mcl_worlds, mcl_init

View file

@ -305,7 +305,7 @@ function awards.unlock(name, award)
else
local player = minetest.get_player_by_name(name)
local one = player:hud_add({
hud_elem_type = "image",
[mcl_vars.hud_type_field] = "image",
name = "award_bg",
scale = {x = 1.25, y = 1},
text = background,
@ -325,7 +325,7 @@ function awards.unlock(name, award)
hud_announce = S("Advancement Made!")
end
local two = player:hud_add({
hud_elem_type = "text",
[mcl_vars.hud_type_field] = "text",
name = "award_au",
number = 0xFFFF00,
scale = {x = 100, y = 20},
@ -336,7 +336,7 @@ function awards.unlock(name, award)
z_index = 102,
})
local three = player:hud_add({
hud_elem_type = "text",
[mcl_vars.hud_type_field] = "text",
name = "award_title",
number = 0xFFFFFF,
scale = {x = 100, y = 20},
@ -351,7 +351,7 @@ function awards.unlock(name, award)
Yes, it's a hack, but it works for all texture sizes and is needed because the image
type does NOT allow us a simple scaling. ]]
local four = player:hud_add({
hud_elem_type = "statbar",
[mcl_vars.hud_type_field] = "statbar",
name = "award_icon",
size = {x=64, y = 64},
number = 2,

View file

@ -6,4 +6,4 @@ license = LGPL 2.1 or later
forum = https://forum.luanti.org/viewtopic.php?t=4870
version = 2.3.0
optional_depends = sfinv, unified_inventory
depends = mcl_colors
depends = mcl_colors, mcl_init

View file

@ -7,6 +7,8 @@ local N = function(s) return s end
local math = math
local table = table
local hud_type_field = mcl_vars.hud_type_field
hb = {
hudtables = {},
-- number of registered HUD bars
@ -207,7 +209,7 @@ function hb.register_hudbar(identifier, text_color, label, textures, direction,
if hb.settings.bar_type == "progress_bar" then
ids.bg = player:hud_add({
hud_elem_type = "image",
[hud_type_field] = "image",
position = pos,
scale = bgscale,
text = "hudbars_bar_background.png",
@ -217,7 +219,7 @@ function hb.register_hudbar(identifier, text_color, label, textures, direction,
})
if textures.icon then
ids.icon = player:hud_add({
hud_elem_type = "image",
[hud_type_field] = "image",
position = pos,
scale = iconscale,
text = textures.icon,
@ -250,7 +252,7 @@ function hb.register_hudbar(identifier, text_color, label, textures, direction,
end
ids.bar = player:hud_add({
hud_elem_type = "statbar",
[hud_type_field] = "statbar",
position = pos,
text = bar_image,
text2 = text2,
@ -264,7 +266,7 @@ function hb.register_hudbar(identifier, text_color, label, textures, direction,
})
if hb.settings.bar_type == "progress_bar" then
ids.text = player:hud_add({
hud_elem_type = "text",
[hud_type_field] = "text",
position = pos,
text = text,
alignment = {x=1,y=1},

View file

@ -1,3 +1,4 @@
name = hudbars
author = Wuzzy
description = Replaces the health and breath symbols in the HUD by “progress bars” and shows exact values. Other mods can add more progress bars for custom player stats.
depends = mcl_init

View file

@ -1,3 +1,5 @@
local hud_type_field = mcl_vars.hud_type_field
mcl_bossbars = {
bars = {},
huds = {},
@ -149,7 +151,7 @@ minetest.register_globalstep(function(dtime)
image = bar.image,
text = bar.text,
text_id = player:hud_add({
hud_elem_type = "text",
[hud_type_field] = "text",
text = bar.text,
number = bar.color,
position = {x = 0.5, y = 0},
@ -157,7 +159,7 @@ minetest.register_globalstep(function(dtime)
offset = {x = 0, y = i * 40},
}),
image_id = player:hud_add({
hud_elem_type = "image",
[hud_type_field] = "image",
text = bar.image,
position = {x = 0.5, y = 0},
alignment = {x = 0, y = 1},

View file

@ -1,4 +1,4 @@
name = mcl_bossbars
author = Fleckenstein
description = Show enderdragon & wither boss bars. Also allows custom bars.
depends = mcl_util, mcl_colors
depends = mcl_util, mcl_colors, mcl_init

View file

@ -29,7 +29,7 @@ function mcl_credits.show(player)
moving = {},
ids = {
player:hud_add({
hud_elem_type = "image",
[mcl_vars.hud_type_field] = "image",
text = "credits_bg.png",
position = {x = 0, y = 0},
alignment = {x = 1, y = 1},
@ -37,7 +37,7 @@ function mcl_credits.show(player)
z_index = 1000,
}),
player:hud_add({
hud_elem_type = "text",
[mcl_vars.hud_type_field] = "text",
text = S("Sneak to skip"),
position = {x = 1, y = 1},
alignment = {x = -1, y = -1},
@ -46,7 +46,7 @@ function mcl_credits.show(player)
number = 0xFFFFFF,
}),
player:hud_add({
hud_elem_type = "text",
[mcl_vars.hud_type_field] = "text",
text = " "..S("Jump to speed up (additionally sprint)"),
position = {x = 0, y = 1},
alignment = {x = 1, y = -1},
@ -57,12 +57,12 @@ function mcl_credits.show(player)
},
}
add_hud_element({
hud_elem_type = "image",
[mcl_vars.hud_type_field] = "image",
text = "voxelibre_logo.png",
scale = {x = 1, y = 1},
}, huds, 300, 0)
add_hud_element({
hud_elem_type = "text",
[mcl_vars.hud_type_field] = "text",
text = mcl_credits.description,
number = 0x757575,
scale = {x = 5, y = 5},
@ -70,7 +70,7 @@ function mcl_credits.show(player)
local y = 450
for _, group in ipairs(mcl_credits.people) do
add_hud_element({
hud_elem_type = "text",
[mcl_vars.hud_type_field] = "text",
text = group[1],
number = group[2],
scale = {x = 3, y = 3},
@ -79,7 +79,7 @@ function mcl_credits.show(player)
for _, name in ipairs(group[3]) do
y = y + 25
add_hud_element({
hud_elem_type = "text",
[mcl_vars.hud_type_field] = "text",
text = name,
number = 0xFFFFFF,
scale = {x = 1, y = 1},
@ -88,7 +88,7 @@ function mcl_credits.show(player)
y = y + 200
end
huds.icon = add_hud_element({
hud_elem_type = "image",
[mcl_vars.hud_type_field] = "image",
text = "voxelibre_icon.png",
scale = {x = 1, y = 1},
}, huds, y)

View file

@ -1,3 +1,4 @@
name = mcl_credits
author = Fleckenstein
description = Show a HUD containing the credits
depends = mcl_init

View file

@ -178,7 +178,7 @@ function mcl_experience.setup_hud(player)
if not minetest.is_creative_enabled(player:get_player_name()) then
hud_bars[player] = player:hud_add({
hud_elem_type = "image",
[mcl_vars.hud_type_field] = "image",
position = { x = 0.5, y = 1 },
offset = { x = (-9 * 28) - 3, y = -(48 + 24 + 16 - 5) },
scale = { x = 0.35, y = 0.375 },
@ -187,7 +187,7 @@ function mcl_experience.setup_hud(player)
})
hud_levels[player] = player:hud_add({
hud_elem_type = "text",
[mcl_vars.hud_type_field] = "text",
position = { x = 0.5, y = 1 },
number = 0x80FF20,
offset = { x = 0, y = -(48 + 24 + 24) },

View file

@ -1,4 +1,4 @@
name = mcl_experience
author = oilboi
description = eXPerience mod
depends = mcl_gamemode, mcl_luck
depends = mcl_gamemode, mcl_luck, mcl_init

View file

@ -76,7 +76,7 @@ local function info()
local hud = huds[name]
if s and not hud then
local def = {
hud_elem_type = "text",
[mcl_vars.hud_type_field] = "text",
alignment = {x = 1, y = -1},
scale = {x = 100, y = 100},
position = {x = 0.0073, y = 0.889},

View file

@ -81,7 +81,7 @@ minetest.register_globalstep(function(dtime)
if not offhand_hud.slot then
offhand_hud.slot = player:hud_add({
hud_elem_type = "image",
[mcl_vars.hud_type_field] = "image",
position = position,
offset = offset,
scale = {x = 0.46875, y = 0.46875},
@ -91,7 +91,7 @@ minetest.register_globalstep(function(dtime)
end
if not offhand_hud.item then
offhand_hud.item = player:hud_add({
hud_elem_type = "image",
[mcl_vars.hud_type_field] = "image",
position = position,
offset = offset,
scale = {x = 0.375, y = 0.375},
@ -105,7 +105,7 @@ minetest.register_globalstep(function(dtime)
if offhand_get_wear(player) > 0 then
local texture = "mcl_wear_bar.png^[colorize:#000000"
offhand_hud.wear_bar_bg = player:hud_add({
hud_elem_type = "image",
[mcl_vars.hud_type_field] = "image",
position = {x = 0.5, y = 1},
offset = {x = -320, y = -13},
scale = {x = 40, y = 3},
@ -113,7 +113,7 @@ minetest.register_globalstep(function(dtime)
z_index = 2,
})
offhand_hud.wear_bar = player:hud_add({
hud_elem_type = "image",
[mcl_vars.hud_type_field] = "image",
position = {x = 0.5, y = 1},
offset = {x = -320, y = -13},
scale = {x = 10, y = 3},
@ -126,7 +126,7 @@ minetest.register_globalstep(function(dtime)
if not offhand_hud.item_count and offhand_get_count(player) > 1 then
offhand_hud.item_count = player:hud_add({
hud_elem_type = "text",
[mcl_vars.hud_type_field] = "text",
position = {x = 0.5, y = 1},
offset = {x = -298, y = -18},
scale = {x = 1, y = 1},

View file

@ -1,3 +1,3 @@
name = mcl_offhand
author = NO11
depends = mcl_inventory
depends = mcl_inventory, mcl_init

View file

@ -83,7 +83,7 @@ minetest.register_on_joinplayer(function(player)
}
local _, hex_color = get_color("white")
huds_idx.title[player] = player:hud_add({
hud_elem_type = "text",
[mcl_vars.hud_type_field] = "text",
position = mcl_title.layout.title.position,
alignment = mcl_title.layout.title.alignment,
text = "",
@ -93,7 +93,7 @@ minetest.register_on_joinplayer(function(player)
z_index = 100,
})
huds_idx.subtitle[player] = player:hud_add({
hud_elem_type = "text",
[mcl_vars.hud_type_field] = "text",
position = mcl_title.layout.subtitle.position,
alignment = mcl_title.layout.subtitle.alignment,
text = "",
@ -103,7 +103,7 @@ minetest.register_on_joinplayer(function(player)
z_index = 100,
})
huds_idx.actionbar[player] = player:hud_add({
hud_elem_type = "text",
[mcl_vars.hud_type_field] = "text",
position = mcl_title.layout.actionbar.position,
offset = { x = 0, y = -210 },
alignment = mcl_title.layout.actionbar.alignment,

View file

@ -1,4 +1,4 @@
name = mcl_title
description = Add an API to add in HUD title
depends = mcl_colors, mcl_util
author = AFCMS
depends = mcl_colors, mcl_util, mcl_init
author = AFCMS

View file

@ -44,7 +44,7 @@ local function set_hud(player)
end
huds[player_name] = player:hud_add({
hud_elem_type = "text",
[mcl_vars.hud_type_field] = "text",
position = {x=0.5, y=1},
offset = off,
alignment = {x=0, y=0},

View file

@ -1,4 +1,5 @@
name = show_wielded_item
author = 4aiman
description = Displays the name of the wielded item.
depends = mcl_init
optional_depends = hudbars

View file

@ -141,7 +141,7 @@ if minetest.get_modpath("mcl_armor") then
local function add_pumpkin_hud(player)
pumpkin_hud[player] = {
pumpkin_blur = player:hud_add({
hud_elem_type = "image",
[mcl_vars.hud_type_field] = "image",
position = {x = 0.5, y = 0.5},
scale = {x = -101, y = -101},
text = "mcl_farming_pumpkin_hud.png",
@ -150,7 +150,7 @@ if minetest.get_modpath("mcl_armor") then
--this is a fake crosshair, because hotbar and crosshair doesn't support z_index
--TODO: remove this and add correct z_index values
fake_crosshair = player:hud_add({
hud_elem_type = "image",
[mcl_vars.hud_type_field] = "image",
position = {x = 0.5, y = 0.5},
scale = {x = 1, y = 1},
text = "crosshair.png",

View file

@ -53,7 +53,7 @@ local function now_playing(player, name)
player:hud_change(id, "text", text)
else
id = player:hud_add({
hud_elem_type = "text",
[mcl_vars.hud_type_field] = "text",
position = { x=0.5, y=0.8 },
offset = { x=0, y = 0 },
number = 0x55FFFF,

View file

@ -1,3 +1,3 @@
name = mcl_jukebox
description = Jukebox and music discs are used to play background music on a per-player basis.
depends = mcl_core, mcl_sounds, mcl_colors
depends = mcl_core, mcl_sounds, mcl_colors, mcl_init

View file

@ -405,7 +405,7 @@ local huds = {}
core.register_on_joinplayer(function(player)
local map_def = {
hud_elem_type = "image",
[mcl_vars.hud_type_field] = "image",
text = "blank.png",
position = { x = 0.75, y = 0.8 },
alignment = { x = 0, y = -1 },

View file

@ -1,3 +1,3 @@
name = mcl_maps
author = wuzzy, fleckenstein, kno10
depends = mcl_core, mcl_flowers, tt, mcl_colors, mcl_skins, mcl_util, mcl_title
depends = mcl_core, mcl_flowers, tt, mcl_colors, mcl_skins, mcl_util, mcl_title, mcl_init

View file

@ -4,6 +4,8 @@ local EF = {}
mcl_potions.registered_effects = {}
local registered_effects = mcl_potions.registered_effects -- shorthand ref
local hud_type_field = mcl_vars.hud_type_field
-- effects affecting item speed utilize numerous hacks, so they have to be counted separately
local item_speed_effects = {}
@ -559,7 +561,7 @@ mcl_potions.register_effect({
player:hud_change(hud_id, "scale", {x = scale, y = scale})
else
EF.glowing[object].waypoints[player] = player:hud_add({
hud_elem_type = "image_waypoint",
[hud_type_field] = "image_waypoint",
position = {x = 0.5, y = 0.5},
scale = {x = scale, y = scale},
text = "mcl_potions_glow_waypoint.png",
@ -773,7 +775,7 @@ mcl_potions.register_effect({
playerphysics.add_physics_factor(object, "speed", "mcl_potions:frost", 1-factor)
if EF.frost[object].vignette then return end
EF.frost[object].vignette = object:hud_add({
hud_elem_type = "image",
[hud_type_field] = "image",
position = {x = 0.5, y = 0.5},
scale = {x = -101, y = -101},
text = "mcl_potions_frost_hud.png",
@ -782,7 +784,7 @@ mcl_potions.register_effect({
end,
on_load = function(object, factor)
EF.frost[object].vignette = object:hud_add({
hud_elem_type = "image",
[hud_type_field] = "image",
position = {x = 0.5, y = 0.5},
scale = {x = -101, y = -101},
text = "mcl_potions_frost_hud.png",
@ -823,7 +825,7 @@ mcl_potions.register_effect({
end,
on_start = function(object, factor)
EF.blindness[object].vignette = object:hud_add({
hud_elem_type = "image",
[hud_type_field] = "image",
position = {x = 0.5, y = 0.5},
scale = {x = -101, y = -101},
text = "mcl_potions_blindness_hud.png",
@ -833,7 +835,7 @@ mcl_potions.register_effect({
end,
on_load = function(object, factor)
EF.blindness[object].vignette = object:hud_add({
hud_elem_type = "image",
[hud_type_field] = "image",
position = {x = 0.5, y = 0.5},
scale = {x = -101, y = -101},
text = "mcl_potions_blindness_hud.png",
@ -1228,7 +1230,7 @@ local function potions_init_icons(player)
local x = -52 * e - 2
local id = {}
id.img = player:hud_add({
hud_elem_type = "image",
[hud_type_field] = "image",
text = "blank.png",
position = { x = 1, y = 0 },
offset = { x = x, y = 3 },
@ -1237,7 +1239,7 @@ local function potions_init_icons(player)
z_index = 100,
})
id.label = player:hud_add({
hud_elem_type = "text",
[hud_type_field] = "text",
text = "",
position = { x = 1, y = 0 },
offset = { x = x+22, y = 50 },
@ -1248,7 +1250,7 @@ local function potions_init_icons(player)
number = 0xFFFFFF,
})
id.timestamp = player:hud_add({
hud_elem_type = "text",
[hud_type_field] = "text",
text = "",
position = { x = 1, y = 0 },
offset = { x = x+22, y = 65 },

View file

@ -1,2 +1,2 @@
name = mcl_potions
depends = mcl_core, mcl_farming, mcl_flowers, mcl_mobitems, mcl_mobs, mcl_fishing, mcl_bows, mcl_end, mcl_weather, playerphysics, mcl_wip, vl_projectile
depends = mcl_core, mcl_farming, mcl_flowers, mcl_mobitems, mcl_mobs, mcl_fishing, mcl_bows, mcl_end, mcl_weather, playerphysics, mcl_wip, vl_projectile, mcl_init

View file

@ -363,7 +363,7 @@ local function add_shield_hud(shieldstack, player, blocking)
player:hud_set_flags({wielditem = false})
end
shield_hud[player] = player:hud_add({
hud_elem_type = "image",
[mcl_vars.hud_type_field] = "image",
position = {x = 0.5, y = 0.5},
scale = {x = -101, y = -101},
offset = {x = offset, y = 0},

View file

@ -1,3 +1,3 @@
name = mcl_shields
author = NO11
depends = mcl_damage, mcl_enchanting, mcl_banners, mcl_util, playerphysics
depends = mcl_damage, mcl_enchanting, mcl_banners, mcl_util, playerphysics, mcl_init

View file

@ -33,7 +33,7 @@ local function add_scope(player)
local wielditem = player:get_wielded_item()
if wielditem:get_name() == "mcl_spyglass:spyglass" then
spyglass_scope[player] = player:hud_add({
hud_elem_type = "image",
[mcl_vars.hud_type_field] = "image",
position = {x = 0.5, y = 0.5},
scale = {x = -100, y = -100},
text = "mcl_spyglass_scope.png",

View file

@ -1,4 +1,4 @@
name = mcl_spyglass
author = NO11
description = This mod adds a spyglass, which is an item that can be used for zooming in on specific locations.
depends = mcl_core, controls, mcl_fovapi
depends = mcl_core, controls, mcl_fovapi, mcl_init

View file

@ -84,7 +84,7 @@ mcl_damage.register_modifier(function(obj, damage, reason)
-- Big totem overlay
if not hud_totem[obj] then
hud_totem[obj] = obj:hud_add({
hud_elem_type = "image",
[mcl_vars.hud_type_field] = "image",
text = "mcl_totems_totem.png",
position = {x = 0.5, y = 1},
scale = {x = 17, y = 17},

View file

@ -1,2 +1,2 @@
name = mcl_totems
depends = mobs_mc, mcl_damage
depends = mobs_mc, mcl_damage, mcl_init

View file

@ -130,7 +130,7 @@ local function init_hud(player)
hb.init_hudbar(player, "exhaustion", mcl_hunger.get_exhaustion(player))
end
mcl_hunger.eat_anim_hud[name] = player:hud_add({
hud_elem_type = "image",
[mcl_vars.hud_type_field] = "image",
text = "blank.png",
position = {x = 0.5, y = 1},
scale = {x = -25, y = -45},

View file

@ -1,4 +1,4 @@
name = mcl_hunger
author = BlockMen
description = Adds a simple hunger meachanic with satiation, food poisoning and different healing.
depends = hudbars
depends = hudbars, mcl_init