ignore self and proper bar size

This commit is contained in:
Casey 2023-10-14 14:01:38 +03:00
parent b3515c737f
commit a37ba81545
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
1 changed files with 7 additions and 5 deletions

View File

@ -18,10 +18,10 @@ local function entityBox(ent)
local hp_rect_bg, hp_rect_fg
if ent.health ~= nil then
hp_rect_bg = hpbar.addRectangle(-1, -0.25, 2, 0.25, options.hpbar.bg)
hp_rect_fg = hpbar.addRectangle(-1, -0.25, 0, 0.25, options.hpbar.fg)
hp_rect_bg = hpbar.addRectangle(0, 0, 100, 15, options.hpbar.bg)
hp_rect_fg = hpbar.addRectangle(0, 0, 0, 15, options.hpbar.fg)
end
local hp_txt = hpbar.addText({ -1, -0.2 }, ent.name, options.hpbar.txt)
local hp_txt = hpbar.addText({ 0, 2 }, ent.name, options.hpbar.txt)
return {
_cube = cube,
@ -33,7 +33,7 @@ local function entityBox(ent)
self._cube.setPosition(entity.x - 0.25, entity.y - 0.25, entity.z - 0.25)
self._hpbar.setPosition(entity.x, entity.y + 0.5, entity.z)
if self._hp_rect_fg ~= nil then
self._hp_rect_fg.setSize(2 * entity.health / entity.maxHealth, 0.25)
self._hp_rect_fg.setSize(100 * entity.health / entity.maxHealth, 15)
end
if entity.health ~= nil then
self._hp_txt.setText(string.format("%s (%.1f/%.1f)", entity.name, entity.health, entity.maxHealth))
@ -59,7 +59,9 @@ return function()
end
for uuid, entity in pairs(surroundings.entitiesByUUID) do
if cache[uuid] == nil then
if uuid == player.id then
-- nothing
elseif cache[uuid] == nil then
cache[uuid] = entityBox(entity)
else
cache[uuid]:update(entity)