Minor statbars update
@ -37,8 +37,6 @@ MultiCraft Development Team:
|
|||||||
textures/base/pack/down_btn.png
|
textures/base/pack/down_btn.png
|
||||||
textures/base/pack/drop_btn.png
|
textures/base/pack/drop_btn.png
|
||||||
textures/base/pack/escape_btn.png
|
textures/base/pack/escape_btn.png
|
||||||
textures/base/pack/heart.png
|
|
||||||
textures/base/pack/heart_gone.png
|
|
||||||
textures/base/pack/hunger_*.png
|
textures/base/pack/hunger_*.png
|
||||||
textures/base/pack/inventory_btn.png
|
textures/base/pack/inventory_btn.png
|
||||||
textures/base/pack/joystick_*.png
|
textures/base/pack/joystick_*.png
|
||||||
@ -105,6 +103,10 @@ Zughy:
|
|||||||
textures/base/pack/cdb_update.png
|
textures/base/pack/cdb_update.png
|
||||||
textures/base/pack/cdb_viewonline.png
|
textures/base/pack/cdb_viewonline.png
|
||||||
|
|
||||||
|
KevDoy, An0n3m0us:
|
||||||
|
textures/base/pack/heart.png
|
||||||
|
textures/base/pack/heart_gone.png
|
||||||
|
|
||||||
License of Minetest source code
|
License of Minetest source code
|
||||||
-------------------------------
|
-------------------------------
|
||||||
|
|
||||||
|
@ -75,6 +75,14 @@ local function is_player(player)
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function get_hud_id(player)
|
||||||
|
return hunger.hud[player:get_player_name()]
|
||||||
|
end
|
||||||
|
|
||||||
|
local function set_hud_id(player, hud_id)
|
||||||
|
hunger.hud[player:get_player_name()] = hud_id
|
||||||
|
end
|
||||||
|
|
||||||
--- SATURATION API ---
|
--- SATURATION API ---
|
||||||
function hunger.get_saturation(player)
|
function hunger.get_saturation(player)
|
||||||
if not is_player(player) then
|
if not is_player(player) then
|
||||||
@ -91,8 +99,7 @@ function hunger.set_hud_level(player, level)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local hud = hunger.hud[player:get_player_name()]
|
player:hud_change(get_hud_id(player), "number", min(settings.visual_max, level))
|
||||||
player:hud_change(hud, "number", min(settings.visual_max, level))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function hunger.set_saturation(player, level)
|
function hunger.set_saturation(player, level)
|
||||||
@ -103,7 +110,7 @@ end
|
|||||||
hunger.registered_on_update_saturations = {}
|
hunger.registered_on_update_saturations = {}
|
||||||
function hunger.register_on_update_saturation(fun)
|
function hunger.register_on_update_saturation(fun)
|
||||||
local saturations = hunger.registered_on_update_saturations
|
local saturations = hunger.registered_on_update_saturations
|
||||||
saturations[#saturations+1] = fun
|
saturations[#saturations + 1] = fun
|
||||||
end
|
end
|
||||||
|
|
||||||
function hunger.update_saturation(player, level)
|
function hunger.update_saturation(player, level)
|
||||||
@ -137,7 +144,13 @@ function hunger.change_saturation(player, change)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local level = hunger.get_saturation(player) + change or 0
|
local old = hunger.get_saturation(player)
|
||||||
|
|
||||||
|
if not old then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local level = old + change
|
||||||
level = max(level, 0)
|
level = max(level, 0)
|
||||||
level = min(level, settings.level_max)
|
level = min(level, settings.level_max)
|
||||||
hunger.update_saturation(player, level)
|
hunger.update_saturation(player, level)
|
||||||
@ -162,9 +175,8 @@ function hunger.set_hud_poisoned(player, poisoned)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local hud = hunger.hud[player:get_player_name()]
|
|
||||||
local texture = poisoned and "hunger_poisen.png" or "hunger.png"
|
local texture = poisoned and "hunger_poisen.png" or "hunger.png"
|
||||||
player:hud_change(hud, "text", texture)
|
player:hud_change(get_hud_id(player), "text", texture)
|
||||||
end
|
end
|
||||||
|
|
||||||
function hunger.set_poisoned(player, poisoned)
|
function hunger.set_poisoned(player, poisoned)
|
||||||
@ -195,7 +207,7 @@ end
|
|||||||
hunger.registered_on_poisons = {}
|
hunger.registered_on_poisons = {}
|
||||||
function hunger.register_on_poison(fun)
|
function hunger.register_on_poison(fun)
|
||||||
local poison = hunger.registered_on_poisons
|
local poison = hunger.registered_on_poisons
|
||||||
poison[#poison+1] = fun
|
poison[#poison + 1] = fun
|
||||||
end
|
end
|
||||||
|
|
||||||
function hunger.poison(player, ticks, interval)
|
function hunger.poison(player, ticks, interval)
|
||||||
@ -236,7 +248,7 @@ end
|
|||||||
hunger.registered_on_exhaust_players = {}
|
hunger.registered_on_exhaust_players = {}
|
||||||
function hunger.register_on_exhaust_player(fun)
|
function hunger.register_on_exhaust_player(fun)
|
||||||
local exhaust = hunger.registered_on_exhaust_players
|
local exhaust = hunger.registered_on_exhaust_players
|
||||||
exhaust[#exhaust+1] = fun
|
exhaust[#exhaust + 1] = fun
|
||||||
end
|
end
|
||||||
|
|
||||||
function hunger.exhaust_player(player, change, cause)
|
function hunger.exhaust_player(player, change, cause)
|
||||||
@ -384,7 +396,8 @@ core.register_on_joinplayer(function(player)
|
|||||||
if hunger.bar_definition then
|
if hunger.bar_definition then
|
||||||
local def = tcopy(hunger.bar_definition)
|
local def = tcopy(hunger.bar_definition)
|
||||||
def.number = min(settings.visual_max, level)
|
def.number = min(settings.visual_max, level)
|
||||||
hunger.hud[player:get_player_name()] = player:hud_add(def)
|
local id = player:hud_add(def)
|
||||||
|
set_hud_id(player, id)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- reset poisoned
|
-- reset poisoned
|
||||||
@ -392,7 +405,7 @@ core.register_on_joinplayer(function(player)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
core.register_on_leaveplayer(function(player)
|
core.register_on_leaveplayer(function(player)
|
||||||
hunger.hud[player:get_player_name()] = nil
|
set_hud_id(player, nil)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local exhaust = hunger.exhaust_player
|
local exhaust = hunger.exhaust_player
|
||||||
@ -409,7 +422,7 @@ core.register_on_punchplayer(function(_, hitter)
|
|||||||
exhaust(hitter, settings.exhaust_punch, hunger.exhaustion_reasons.punch)
|
exhaust(hitter, settings.exhaust_punch, hunger.exhaustion_reasons.punch)
|
||||||
end)
|
end)
|
||||||
core.register_on_respawnplayer(function(player)
|
core.register_on_respawnplayer(function(player)
|
||||||
hunger.set_saturation(player, settings.level_max)
|
hunger.update_saturation(player, settings.level_max)
|
||||||
hunger.set_exhaustion(player, 0)
|
hunger.set_exhaustion(player, 0)
|
||||||
hunger.set_poisoned(player, false)
|
hunger.set_poisoned(player, false)
|
||||||
end)
|
end)
|
||||||
|
Before Width: | Height: | Size: 344 B After Width: | Height: | Size: 279 B |
Before Width: | Height: | Size: 212 B After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 366 B After Width: | Height: | Size: 427 B |
Before Width: | Height: | Size: 226 B After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 424 B After Width: | Height: | Size: 364 B |