Update init.lua

This commit is contained in:
LoneWolfHT 2021-10-07 10:33:54 -07:00 committed by GitHub
parent 5c2cb597b8
commit bb270cd035
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -50,7 +50,11 @@ minetest.register_entity("gauges:hp_bar", {
return
end
local hp = min(math.ceil((player:get_hp() / player:get_properties().hp_max) * 20), 20)
-- hp calc credit: https://github.com/minetest/minetest/blob/6de8d77e17017cd5cc7b065d42566b6b1cd076cc/builtin/game/statbars.lua#L30-L37
local current = player:get_hp()
local max_display = math.max(20, math.max(player:get_properties().hp_max, current))
local hp = current / max_display * 20
local breath = min(player:get_breath(), max_breath)
if self.hp ~= hp or self.breath ~= breath then