forked from MineClone5/MineClone5
Name tags now name all mobs (except ender dragon)
This commit is contained in:
parent
d0cdb0f390
commit
69b3e19c1b
|
@ -2958,6 +2958,42 @@ end
|
|||
|
||||
mobs.spawning_mobs = {}
|
||||
|
||||
-- Code to execute before custom on_rightclick handling
|
||||
local on_rightclick_prefix = function(self, clicker)
|
||||
local item = clicker:get_wielded_item()
|
||||
|
||||
-- Name mob with nametag
|
||||
if not self.ignores_nametag and item:get_name() == "mobs:nametag" then
|
||||
|
||||
local tag = item:get_meta():get_string("name")
|
||||
if tag ~= "" then
|
||||
if string.len(tag) > MAX_MOB_NAME_LENGTH then
|
||||
tag = string.sub(tag, 1, MAX_MOB_NAME_LENGTH)
|
||||
end
|
||||
self.nametag = tag
|
||||
|
||||
update_tag(self)
|
||||
|
||||
if not mobs.is_creative(name) then
|
||||
item:take_item()
|
||||
player:set_wielded_item(item)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local create_mob_on_rightclick = function(on_rightclick)
|
||||
return function(self, clicker)
|
||||
local stop = on_rightclick_prefix(self, clicker)
|
||||
if (not stop) and (on_rightclick) then
|
||||
on_rightclick(self, clicker)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- register mob entity
|
||||
function mobs:register_mob(name, def)
|
||||
|
||||
|
@ -3000,7 +3036,7 @@ minetest.register_entity(name, {
|
|||
fall_speed = def.fall_speed or -10, -- must be lower than -2 (default: -10)
|
||||
drops = def.drops or {},
|
||||
armor = def.armor or 100,
|
||||
on_rightclick = def.on_rightclick,
|
||||
on_rightclick = create_mob_on_rightclick(def.on_rightclick),
|
||||
arrow = def.arrow,
|
||||
shoot_interval = def.shoot_interval,
|
||||
sounds = def.sounds or {},
|
||||
|
@ -3059,6 +3095,9 @@ minetest.register_entity(name, {
|
|||
facing_fence = false,
|
||||
_cmi_is_mob = true,
|
||||
|
||||
-- MCL2 extensions
|
||||
ignores_nametag = def.ignores_nametag or false,
|
||||
|
||||
on_spawn = def.on_spawn,
|
||||
|
||||
on_blast = def.on_blast or do_tnt,
|
||||
|
@ -3853,28 +3892,6 @@ function mobs:feed_tame(self, clicker, feed_count, breed, tame)
|
|||
return true
|
||||
end
|
||||
|
||||
local item = clicker:get_wielded_item()
|
||||
|
||||
-- Name mob with nametag
|
||||
if item:get_name() == "mobs:nametag" then
|
||||
|
||||
local tag = item:get_meta():get_string("name")
|
||||
if tag ~= "" then
|
||||
if string.len(tag) > MAX_MOB_NAME_LENGTH then
|
||||
tag = string.sub(tag, 1, MAX_MOB_NAME_LENGTH)
|
||||
end
|
||||
self.nametag = tag
|
||||
|
||||
update_tag(self)
|
||||
|
||||
if not mobs.is_creative(name) then
|
||||
item:take_item()
|
||||
player:set_wielded_item(item)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
|
|
|
@ -205,6 +205,11 @@ functions needed for the mob to work properly which contains the following:
|
|||
older mobs.
|
||||
|
||||
|
||||
MineClone 2 extensions:
|
||||
|
||||
'ignores_nametag' if true, mob cannot be named by nametag
|
||||
|
||||
|
||||
Node Replacement
|
||||
----------------
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ local S = mobs.intllib
|
|||
-- name tag
|
||||
minetest.register_craftitem("mobs:nametag", {
|
||||
description = S("Name Tag"),
|
||||
_doc_items_longdesc = S("A name tag is an item to name an animal."),
|
||||
_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."),
|
||||
_doc_items_longdesc = S("A name tag is an item to name a mob."),
|
||||
_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 a mob with a rightclick. This uses up the name tag."),
|
||||
inventory_image = "mobs_nametag.png",
|
||||
wield_image = "mobs_nametag.png",
|
||||
stack_max = 64,
|
||||
|
|
|
@ -93,6 +93,8 @@ mobs:register_mob("mobs_mc:enderdragon", {
|
|||
run_start = 0, run_end = 20,
|
||||
},
|
||||
blood_amount = 0,
|
||||
|
||||
ignores_nametag = true,
|
||||
})
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue