forked from mtcontrib/minetest_hbhunger
Use HUD bars mod to show player's saturation level
This commit is contained in:
parent
ee92b518ea
commit
00accc22ec
@ -1,3 +1,4 @@
|
|||||||
|
hudbars
|
||||||
default
|
default
|
||||||
animalmaterials?
|
animalmaterials?
|
||||||
bucket?
|
bucket?
|
||||||
|
28
init.lua
28
init.lua
@ -27,35 +27,17 @@ if set then
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function custom_hud(player)
|
local function custom_hud(player)
|
||||||
local name = player:get_player_name()
|
|
||||||
|
|
||||||
if minetest.setting_getbool("enable_damage") then
|
if minetest.setting_getbool("enable_damage") then
|
||||||
--hunger
|
--hunger
|
||||||
player:hud_add({
|
hb.init_hudbar(player, "saturation")
|
||||||
hud_elem_type = "statbar",
|
|
||||||
position = HUD_HUNGER_POS,
|
|
||||||
size = HUD_SIZE,
|
|
||||||
text = "hud_hunger_bg.png",
|
|
||||||
number = 20,
|
|
||||||
alignment = {x=-1,y=-1},
|
|
||||||
offset = HUD_HUNGER_OFFSET,
|
|
||||||
})
|
|
||||||
local h = hunger.hunger[name]
|
|
||||||
if h == nil or h > 20 then h = 20 end
|
|
||||||
hunger_hud[name] = player:hud_add({
|
|
||||||
hud_elem_type = "statbar",
|
|
||||||
position = HUD_HUNGER_POS,
|
|
||||||
size = HUD_SIZE,
|
|
||||||
text = "hud_hunger_fg.png",
|
|
||||||
number = h,
|
|
||||||
alignment = {x=-1,y=-1},
|
|
||||||
offset = HUD_HUNGER_OFFSET,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
dofile(minetest.get_modpath("hunger").."/hunger.lua")
|
dofile(minetest.get_modpath("hunger").."/hunger.lua")
|
||||||
|
|
||||||
|
-- register saturation hudbar
|
||||||
|
hb.register_hudbar("saturation", 0xFFFFFF, "Saturation", { icon = "hunger_icon.png", bar = "hunger_bar.png" }, 20, 20, false)
|
||||||
|
|
||||||
-- update hud elemtens if value has changed
|
-- update hud elemtens if value has changed
|
||||||
local function update_hud(player)
|
local function update_hud(player)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
@ -66,7 +48,7 @@ local function update_hud(player)
|
|||||||
hunger.hunger_out[name] = h
|
hunger.hunger_out[name] = h
|
||||||
-- bar should not have more than 10 icons
|
-- bar should not have more than 10 icons
|
||||||
if h>20 then h=20 end
|
if h>20 then h=20 end
|
||||||
player:hud_change(hunger_hud[name], "number", h)
|
hb.change_hudbar(player, "saturation", h)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
BIN
textures/hunger_bar.png
Normal file
BIN
textures/hunger_bar.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 80 B |
Before Width: | Height: | Size: 522 B After Width: | Height: | Size: 522 B |
Loading…
Reference in New Issue
Block a user