Add multiplayer support for pumpkin hud

This commit is contained in:
NO11 2021-05-23 22:31:13 +00:00
parent 9b9ec13967
commit 8b11e2fec8
1 changed files with 27 additions and 19 deletions

View File

@ -124,26 +124,32 @@ pumpkin_face_base_def._mcl_armor_preview = "mcl_farming_pumpkin_face_preview.png
if minetest.get_modpath("mcl_armor") then if minetest.get_modpath("mcl_armor") then
local pumpkin_hud = {} local pumpkin_hud = {}
local add_pumpkin_hud = function(player) local add_pumpkin_hud = function(player)
pumpkin_hud = player:hud_add({ local name = player:get_player_name()
pumpkin_hud[name] = {
pumpkin_blur = player:hud_add({
hud_elem_type = "image", hud_elem_type = "image",
position = {x = 0.5, y = 0.5}, position = {x = 0.5, y = 0.5},
scale = {x = -100, y = -100}, scale = {x = -100, y = -100},
text = "mcl_farming_pumpkin_hud.png", text = "mcl_farming_pumpkin_hud.png",
z_index = -200 z_index = -200
}) }),
--this is a fake crosshair, because hotbar and crosshair doesn't support z_index --this is a fake crosshair, because hotbar and crosshair doesn't support z_index
--TODO: remove this and add correct z_index values when this is fixed: https://github.com/minetest/minetest/issues/9270 --TODO: remove this and add correct z_index values
player:hud_add({ fake_crosshair = player:hud_add({
hud_elem_type = "image", hud_elem_type = "image",
position = {x = 0.5, y = 0.5}, position = {x = 0.5, y = 0.5},
scale = {x = 1, y = 1}, scale = {x = 1, y = 1},
text = "crosshair.png", text = "crosshair.png",
z_index = -100 z_index = -100
}) })
}
end end
local remove_pumpkin_hud = function(player) local remove_pumpkin_hud = function(player)
if pumpkin_hud then local name = player:get_player_name()
player:hud_remove(pumpkin_hud) if pumpkin_hud[name] then
player:hud_remove(pumpkin_hud[name].pumpkin_blur)
player:hud_remove(pumpkin_hud[name].fake_crosshair)
pumpkin_hud[name] = nil
end end
end end
@ -157,10 +163,12 @@ if minetest.get_modpath("mcl_armor") then
add_pumpkin_hud(player) add_pumpkin_hud(player)
end end
end) end)
minetest.register_on_dieplayer(function(player) minetest.register_on_dieplayer(function(player)
remove_pumpkin_hud(player) remove_pumpkin_hud(player)
end) end)
minetest.register_on_leaveplayer(function(player)
remove_pumpkin_hud(player)
end)
end end
-- Register stem growth -- Register stem growth