forked from MineClone5/MineClone5
Require naming of name tag before it's usable
This commit is contained in:
parent
449fc046dd
commit
15d7764c65
|
@ -333,24 +333,8 @@ end
|
||||||
-- update nametag colour
|
-- update nametag colour
|
||||||
local update_tag = function(self)
|
local update_tag = function(self)
|
||||||
|
|
||||||
local col = "#00FF00"
|
|
||||||
local qua = self.hp_max / 4
|
|
||||||
|
|
||||||
if self.health <= floor(qua * 3) then
|
|
||||||
col = "#FFFF00"
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.health <= floor(qua * 2) then
|
|
||||||
col = "#FF6600"
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.health <= floor(qua) then
|
|
||||||
col = "#FF0000"
|
|
||||||
end
|
|
||||||
|
|
||||||
self.object:set_properties({
|
self.object:set_properties({
|
||||||
nametag = self.nametag,
|
nametag = self.nametag,
|
||||||
nametag_color = col
|
|
||||||
})
|
})
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -3539,10 +3523,6 @@ function mobs:protect(self, clicker)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local mob_obj = {}
|
|
||||||
local mob_sta = {}
|
|
||||||
|
|
||||||
-- feeding, taming and breeding (thanks blert2112)
|
-- feeding, taming and breeding (thanks blert2112)
|
||||||
function mobs:feed_tame(self, clicker, feed_count, breed, tame)
|
function mobs:feed_tame(self, clicker, feed_count, breed, tame)
|
||||||
|
|
||||||
|
@ -3624,72 +3604,27 @@ function mobs:feed_tame(self, clicker, feed_count, breed, tame)
|
||||||
|
|
||||||
local item = clicker:get_wielded_item()
|
local item = clicker:get_wielded_item()
|
||||||
|
|
||||||
-- if mob has been tamed you can name it with a nametag
|
-- Name mob with nametag
|
||||||
if item:get_name() == "mobs:nametag"
|
if item:get_name() == "mobs:nametag" then
|
||||||
and clicker:get_player_name() == self.owner then
|
|
||||||
|
|
||||||
local name = clicker:get_player_name()
|
local tag = item:get_meta():get_string("name")
|
||||||
|
if string.len(tag) > 30 then
|
||||||
|
tag = string.sub(tag, 1, 30)
|
||||||
|
end
|
||||||
|
self.nametag = tag
|
||||||
|
|
||||||
-- store mob and nametag stack in external variables
|
update_tag(self)
|
||||||
mob_obj[name] = self
|
|
||||||
mob_sta[name] = item
|
|
||||||
|
|
||||||
local tag = self.nametag or ""
|
|
||||||
|
|
||||||
minetest.show_formspec(name, "mobs_nametag", "size[8,4]"
|
|
||||||
.. mcl_vars.gui_bg
|
|
||||||
.. mcl_vars.gui_bg_img
|
|
||||||
.. "field[0.5,1;7.5,0;name;" .. minetest.formspec_escape(S("Enter name:")) .. ";" .. tag .. "]"
|
|
||||||
.. "button_exit[2.5,3.5;3,1;mob_rename;" .. minetest.formspec_escape(S("Rename")) .. "]")
|
|
||||||
|
|
||||||
|
if not mobs.is_creative(name) then
|
||||||
|
item:take_item()
|
||||||
|
player:set_wielded_item(item)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- inspired by blockmen's nametag mod
|
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
||||||
|
|
||||||
-- right-clicked with nametag and name entered?
|
|
||||||
if formname == "mobs_nametag"
|
|
||||||
and fields.name
|
|
||||||
and fields.name ~= "" then
|
|
||||||
|
|
||||||
local name = player:get_player_name()
|
|
||||||
|
|
||||||
if not mob_obj[name]
|
|
||||||
or not mob_obj[name].object then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- limit name entered to 64 characters long
|
|
||||||
if string.len(fields.name) > 64 then
|
|
||||||
fields.name = string.sub(fields.name, 1, 64)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- update nametag
|
|
||||||
mob_obj[name].nametag = fields.name
|
|
||||||
|
|
||||||
update_tag(mob_obj[name])
|
|
||||||
|
|
||||||
-- if not in creative then take item
|
|
||||||
if not mobs.is_creative(name) then
|
|
||||||
|
|
||||||
mob_sta[name]:take_item()
|
|
||||||
|
|
||||||
player:set_wielded_item(mob_sta[name])
|
|
||||||
end
|
|
||||||
|
|
||||||
-- reset external variables
|
|
||||||
mob_obj[name] = nil
|
|
||||||
mob_sta[name] = nil
|
|
||||||
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
|
||||||
-- compatibility function for old entities to new modpack entities
|
-- compatibility function for old entities to new modpack entities
|
||||||
function mobs:alias_mob(old_name, new_name)
|
function mobs:alias_mob(old_name, new_name)
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@ local S = mobs.intllib
|
||||||
-- name tag
|
-- name tag
|
||||||
minetest.register_craftitem("mobs:nametag", {
|
minetest.register_craftitem("mobs:nametag", {
|
||||||
description = S("Name Tag"),
|
description = S("Name Tag"),
|
||||||
_doc_items_longdesc = S("A name tag is an item to name most animals and monsters."),
|
_doc_items_longdesc = S("A name tag is an item to name an animal."),
|
||||||
_doc_items_usagehelp = S("Rightclick an animal or monster while holding the name tag, then enter a name."),
|
_doc_items_usagehelp = S("Before you use the name tag, you need to set a name at an anvil. Now you can use the name tag to name an animal with a rightclick. This uses up the name tag."),
|
||||||
inventory_image = "mobs_nametag.png",
|
inventory_image = "mobs_nametag.png",
|
||||||
wield_image = "mobs_nametag.png",
|
wield_image = "mobs_nametag.png",
|
||||||
stack_max = 64,
|
stack_max = 64,
|
||||||
|
|
Loading…
Reference in New Issue