mobs_redo: add "owner" infotext

This commit is contained in:
MoNTE48 2020-03-28 16:48:02 +01:00
parent 817296da00
commit f877496331

View File

@ -71,6 +71,7 @@ local mob_class = {
stepheight = 1.1, stepheight = 1.1,
fly_in = "air", fly_in = "air",
owner = "", owner = "",
infotext = "",
order = "", order = "",
jump_height = 4, jump_height = 4,
lifetimer = lifetime, lifetimer = lifetime,
@ -1076,12 +1077,12 @@ function mob_class:breed()
if ent.name == self.name then if ent.name == self.name then
canmate = true canmate = true
else else
local entname = string.split(ent.name, ":") local entname = ent.name:split(":")
local selfname = string.split(self.name, ":") local selfname = self.name:split(":")
if entname[1] == selfname[1] then if entname[1] == selfname[1] then
entname = string.split(entname[2], "_") entname = entname[2]:split("_")
selfname = string.split(selfname[2], "_") selfname = selfname[2]:split("_")
if entname[1] == selfname[1] then if entname[1] == selfname[1] then
canmate = true canmate = true
@ -1124,6 +1125,8 @@ function mob_class:breed()
textures = self.child_texture[1] textures = self.child_texture[1]
end end
local infotext = Sl("Owned by @1", Sl(self.owner))
-- and resize to half height -- and resize to half height
mob:set_properties({ mob:set_properties({
textures = textures, textures = textures,
@ -1146,12 +1149,14 @@ function mob_class:breed()
self.base_selbox[4] * .5, self.base_selbox[4] * .5,
self.base_selbox[5] * .5, self.base_selbox[5] * .5,
self.base_selbox[6] * .5 self.base_selbox[6] * .5
} },
infotext = infotext
}) })
-- tamed and owned by parents' owner -- tamed and owned by parents' owner
ent2.child = true ent2.child = true
ent2.tamed = true ent2.tamed = true
ent2.owner = self.owner ent2.owner = self.owner
ent2.infotext = infotext
end, self, ent) end, self, ent)
num = 0 num = 0
break break
@ -3319,8 +3324,14 @@ local function spawn_mob(pos, mob, data, placer)
if ent then if ent then
-- set owner if not a monster -- set owner if not a monster
if ent.type ~= "monster" then if ent.type ~= "monster" then
ent.owner = placer:get_player_name() local pn = placer:get_player_name()
ent.owner = pn
ent.tamed = true ent.tamed = true
local infotext = Sl("Owned by @1", Sl(pn))
ent.infotext = infotext
obj:set_properties({
infotext = infotext
})
end end
return true return true
else else
@ -3633,9 +3644,15 @@ function mobs:feed_tame(self, clicker, feed_count, breed, tame)
end end
self.tamed = true self.tamed = true
if not self.owner or self.owner == "" then if not self.owner or self.owner == "" then
self.owner = clicker:get_player_name() local pn = clicker:get_player_name()
self.owner = pn
local infotext = Sl("Owned by @1", Sl(pn))
self.infotext = infotext
self.object:set_properties({
infotext = infotext
})
end end
end end
@ -3682,8 +3699,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if item:get_name() ~= "mobs:nametag" then return end if item:get_name() ~= "mobs:nametag" then return end
-- limit name entered to 64 characters long -- limit name entered to 64 characters long
if string.len(fields.name) > 64 then if fields.name:len() > 64 then
fields.name = string.sub(fields.name, 1, 64) fields.name = fields.name:sub(1, 64)
end end
-- update nametag -- update nametag