1
0
mirror of https://github.com/Sokomine/cottages.git synced 2026-01-10 02:55:50 +01:00

fixed broken hud in multiplayer

This commit is contained in:
Sokomine
2025-09-06 16:01:56 +02:00
parent 275d6c2068
commit c93c1857c6
4 changed files with 67 additions and 50 deletions

36
hud_functions.lua Normal file
View File

@@ -0,0 +1,36 @@
-- store for which player we're showing which huds
cottages.hud_wait = {}
-- remove all huds that were shown to the player via cottages.add_hud_list
cottages.unshow_hud_list = function(puncher)
if(not(puncher) or not(cottages.hud_wait[puncher])) then
return
end
for i, hud_id in ipairs(cottages.hud_wait[puncher] or {}) do
if(puncher and hud_id) then
puncher:hud_remove(hud_id)
end
end
cottages.hud_wait[puncher] = nil
end
-- show a list of huds to puncher and remove them after delay seconds
cottages.add_hud_list = function(puncher, delay, hud_list)
if(not(puncher) or not(hud_list) or not(delay)) then
return
end
if(cottages.hud_wait[puncher]) then
-- if necessary, remove all currently shown huds (it would get
-- pretty messy if we had overlaying huds here)
cottages.unshow_hud_list(puncher)
end
-- start with a new, clear list
cottages.hud_wait[puncher] = {}
for i, hud_def in ipairs(hud_list or {}) do
local hud_id = puncher:hud_add(hud_def)
table.insert(cottages.hud_wait[puncher], hud_id)
end
minetest.after(delay, cottages.unshow_hud_list, puncher)
end

View File

@@ -81,6 +81,9 @@ cottages.handmill_min_per_turn = 0;
dofile(minetest.get_modpath("cottages").."/functions.lua");
-- anvil and threshing floor show huds
dofile(minetest.get_modpath("cottages").."/hud_functions.lua");
-- uncomment parts you do not want
dofile(minetest.get_modpath("cottages").."/nodes_furniture.lua");
dofile(minetest.get_modpath("cottages").."/nodes_historic.lua");

View File

@@ -216,7 +216,7 @@ minetest.register_node("cottages:anvil", {
end
end
local hud1 = puncher:hud_add({
local hud_list = {{
name = "cottages_anvil_broken_tool_img",
direction = 0,
z_index = 90,
@@ -225,11 +225,9 @@ minetest.register_node("cottages:anvil", {
text = hud_image,
position = {x = 0.5, y = 0.5},
alignment = {x = 0, y = 0}
});
local hud2 = nil;
local hud3 = nil;
}}
if( input:get_wear()>0 ) then
hud2 = puncher:hud_add({
table.insert(hud_list, {
name = "cottages_anvil_wear_red",
z_index = 111,
type = "statbar",
@@ -241,7 +239,7 @@ minetest.register_node("cottages:anvil", {
offset = {x = -320, y = 0},
size = {x=32, y=32},
})
hud3 = puncher:hud_add({
table.insert(hud_list, {
name = "cottages_anvil_wear_green",
z_index = 112,
type = "statbar",
@@ -252,15 +250,10 @@ minetest.register_node("cottages:anvil", {
alignment = {x = 0, y = 0},
offset = {x = -320, y = 0},
size = {x=32, y=32},
});
})
end
minetest.after(2, function()
if( puncher ) then
if(hud1) then puncher:hud_remove(hud1); end
if(hud2) then puncher:hud_remove(hud2); end
if(hud3) then puncher:hud_remove(hud3); end
end
end)
-- show the hud list (removing them later on is handled automaticly)
cottages.add_hud_list(puncher, 2, hud_list)
-- tell the player when the job is done
if( input:get_wear() == 0 ) then

View File

@@ -220,6 +220,11 @@ minetest.register_node("cottages:threshing_floor", {
if( not( pos ) or not( node ) or not( puncher )) then
return;
end
-- too fast punching - either from anvil or from threshing floor
if(cottages.hud_wait[puncher]) then
return
end
-- only punching with a normal stick is supposed to work
local wielded = puncher:get_wielded_item();
if( not( wielded )
@@ -306,6 +311,12 @@ minetest.register_node("cottages:threshing_floor", {
inv:remove_item("harvest", crop_name..' '..tostring( anz_wheat ))
local anz_left = found_wheat - anz_wheat;
if( not( anz_straw )) then
anz_straw = "0";
end
if( not( anz_seeds )) then
anz_seeds = "0"
end
if( anz_left > 0 ) then
-- minetest.chat_send_player( name, S('You have threshed %s wheat (%s are left).'):format(anz_wheat,anz_left));
else
@@ -313,7 +324,7 @@ minetest.register_node("cottages:threshing_floor", {
overlay1 = "";
end
local hud0 = puncher:hud_add({
local hud_list = {{
name = "cottages_threshing_floor_base",
direction = 0,
z_index = 110,
@@ -322,9 +333,7 @@ minetest.register_node("cottages:threshing_floor", {
text = "cottages_junglewood.png^[colorize:#888888:128",
position = {x = 0.5, y = 0.5},
alignment = {x = 0, y = 0}
});
local hud1 = puncher:hud_add({
}, {
name = "cottages_threshing_floor_overlay1",
direction = 0,
z_index = 111,
@@ -333,8 +342,7 @@ minetest.register_node("cottages:threshing_floor", {
text = "cottages_junglewood.png"..overlay1,
position = {x = 0.4, y = 0.5},
alignment = {x = 0, y = 0}
});
local hud2 = puncher:hud_add({
}, {
name = "cottages_threshing_floor_overlay2",
direction = 0,
z_index = 112,
@@ -343,8 +351,7 @@ minetest.register_node("cottages:threshing_floor", {
text = "cottages_junglewood.png"..overlay2,
position = {x = 0.6, y = 0.35},
alignment = {x = 0, y = 0}
});
local hud3 = puncher:hud_add({
}, {
name = "cottages_threshing_floor_overlay3",
direction = 0,
z_index = 113,
@@ -353,9 +360,7 @@ minetest.register_node("cottages:threshing_floor", {
text = "cottages_junglewood.png"..overlay3,
position = {x = 0.6, y = 0.65},
alignment = {x = 0, y = 0}
});
local hud4 = puncher:hud_add({
}, {
name = "cottages_threshing_floor_remaining",
direction = 0,
z_index = 114,
@@ -365,14 +370,7 @@ minetest.register_node("cottages:threshing_floor", {
alignment = {x = 0, y = 0},
scale = {x = 100, y = 100}, -- bounding rectangle of the text
position = {x = 0.4, y = 0.5},
});
if( not( anz_straw )) then
anz_straw = "0";
end
if( not( anz_seeds )) then
anz_seeds = "0"
end
local hud5 = puncher:hud_add({
}, {
name = "cottages_threshing_floor_anz_straw",
direction = 0,
z_index = 115,
@@ -382,8 +380,7 @@ minetest.register_node("cottages:threshing_floor", {
alignment = {x = 0, y = 0},
scale = {x = 100, y = 100}, -- bounding rectangle of the text
position = {x = 0.6, y = 0.35},
});
local hud6 = puncher:hud_add({
}, {
name = "cottages_threshing_floor_anz_seeds",
direction = 0,
z_index = 116,
@@ -393,21 +390,9 @@ minetest.register_node("cottages:threshing_floor", {
alignment = {x = 0, y = 0},
scale = {x = 100, y = 100}, -- bounding rectangle of the text
position = {x = 0.6, y = 0.65},
});
minetest.after(2, function()
if( puncher ) then
if(hud1) then puncher:hud_remove(hud1); end
if(hud2) then puncher:hud_remove(hud2); end
if(hud3) then puncher:hud_remove(hud3); end
if(hud4) then puncher:hud_remove(hud4); end
if(hud5) then puncher:hud_remove(hud5); end
if(hud6) then puncher:hud_remove(hud6); end
if(hud0) then puncher:hud_remove(hud0); end
end
end)
}}
-- show those huds to the player (and hide them after 2 secons)
cottages.add_hud_list(puncher, 2, hud_list)
end,
})