change self.nametag to self._nametag (get_properties causing issue)

This commit is contained in:
tenplus1 2023-10-05 12:56:15 +01:00
parent c173345135
commit 6172203e0e
1 changed files with 35 additions and 33 deletions

68
api.lua
View File

@ -730,24 +730,37 @@ local CHILD_GROW_TIME = 60 * 20 -- 20 minutes
-- update nametag and infotext -- update nametag and infotext
function mob_class:update_tag() function mob_class:update_tag(newname)
local col local col
local prop = self.object:get_properties() local prop = self.object:get_properties()
local qua = prop.hp_max / 6 local qua = prop.hp_max / 6
if self.health <= qua then -- backwards compatibility
col = "#FF0000" if self.nametag and self.nametag ~= "" then
elseif self.health <= (qua * 2) then newname = self.nametag
col = "#FF7A00" self.nametag = nil
elseif self.health <= (qua * 3) then end
col = "#FFB500"
elseif self.health <= (qua * 4) then if newname or (self._nametag and self._nametag ~= "") then
col = "#FFFF00"
elseif self.health <= (qua * 5) then self._nametag = newname or self._nametag -- adopt new name if one found
col = "#B4FF00"
elseif self.health > (qua * 5) then if self.health <= qua then
col = "#00FF00" col = "#FF0000"
elseif self.health <= (qua * 2) then
col = "#FF7A00"
elseif self.health <= (qua * 3) then
col = "#FFB500"
elseif self.health <= (qua * 4) then
col = "#FFFF00"
elseif self.health <= (qua * 5) then
col = "#B4FF00"
elseif self.health > (qua * 5) then
col = "#00FF00"
end
self.object:set_properties({nametag = self._nametag, nametag_color = col})
end end
local text = "" local text = ""
@ -773,9 +786,8 @@ function mob_class:update_tag()
.. (self.owner == "" and "" or "\nOwner: " .. self.owner) .. (self.owner == "" and "" or "\nOwner: " .. self.owner)
.. text .. text
-- set changes -- set infotext changes
self.object:set_properties({ self.object:set_properties({infotext = self.infotext})
nametag = self.nametag, nametag_color = col, infotext = self.infotext})
end end
@ -1078,10 +1090,10 @@ end
-- environmental damage (water, lava, fire, light etc.) -- environmental damage (water, lava, fire, light etc.)
function mob_class:do_env_damage() function mob_class:do_env_damage()
self:update_tag()
local pos = self.object:get_pos() ; if not pos then return end local pos = self.object:get_pos() ; if not pos then return end
self:update_tag()
self.time_of_day = minetest.get_timeofday() self.time_of_day = minetest.get_timeofday()
-- halt mob if standing inside ignore node -- halt mob if standing inside ignore node
@ -3153,9 +3165,9 @@ function mob_class:mob_staticdata()
make_footstep_sound = self.make_footstep_sound, make_footstep_sound = self.make_footstep_sound,
stepheight = self.stepheight, stepheight = self.stepheight,
glow = self.glow, glow = self.glow,
nametag = self.nametag, -- nametag = self.nametag,
damage_texture_modifier = self.damage_texture_modifier, damage_texture_modifier = self.damage_texture_modifier,
infotext = self.infotext -- infotext = self.infotext
} }
end end
@ -3295,13 +3307,8 @@ function mob_class:mob_activate(staticdata, def, dtime)
self.standing_in = "air" self.standing_in = "air"
self.standing_on = "air" self.standing_on = "air"
-- check for existing nametag
self.nametag = self.nametag or def.nametag
-- set anything changed above -- set anything changed above
-- self.object:set_properties(self)
self:set_yaw((random(0, 360) - 180) / 180 * pi, 6) self:set_yaw((random(0, 360) - 180) / 180 * pi, 6)
self:update_tag()
self:set_animation("stand") self:set_animation("stand")
-- apply any texture mods -- apply any texture mods
@ -3913,10 +3920,7 @@ function mobs:add_mob(pos, def)
def.nametag = def.nametag:sub(1, 64) def.nametag = def.nametag:sub(1, 64)
end end
mob:set_properties({nametag = def.nametag}) ent:update_tag(def.nametag)
ent.nametag = def.nametag
ent:update_tag()
end end
return ent return ent
@ -4764,7 +4768,7 @@ function mobs:feed_tame(self, clicker, feed_count, breed, tame)
mob_sta[name] = item mob_sta[name] = item
local prop = self.object:get_properties() local prop = self.object:get_properties()
local tag = prop.nametag or "" local tag = self._nametag or ""
local esc = minetest.formspec_escape local esc = minetest.formspec_escape
minetest.show_formspec(name, "mobs_nametag", "size[8,4]" minetest.show_formspec(name, "mobs_nametag", "size[8,4]"
@ -4819,9 +4823,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
-- update nametag -- update nametag
mob_obj[name].object:set_properties({nametag = fields.name}) mob_obj[name]:update_tag(fields.name)
mob_obj[name].nametag = fields.name
mob_obj[name]:update_tag()
-- if not in creative then take item -- if not in creative then take item
if not mobs.is_creative(name) then if not mobs.is_creative(name) then