From 69b3e19c1bd46aca6b80d0ad05662bc6f6dc9242 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Wed, 30 May 2018 11:34:17 +0200 Subject: [PATCH] Name tags now name all mobs (except ender dragon) --- mods/ENTITIES/mobs/api.lua | 63 ++++++++++++++++---------- mods/ENTITIES/mobs/api.txt | 5 ++ mods/ENTITIES/mobs/crafts.lua | 4 +- mods/ENTITIES/mobs_mc/ender_dragon.lua | 2 + 4 files changed, 49 insertions(+), 25 deletions(-) diff --git a/mods/ENTITIES/mobs/api.lua b/mods/ENTITIES/mobs/api.lua index 708e10c00c..d126c0db18 100644 --- a/mods/ENTITIES/mobs/api.lua +++ b/mods/ENTITIES/mobs/api.lua @@ -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 diff --git a/mods/ENTITIES/mobs/api.txt b/mods/ENTITIES/mobs/api.txt index 324ae90a19..c2cd327319 100644 --- a/mods/ENTITIES/mobs/api.txt +++ b/mods/ENTITIES/mobs/api.txt @@ -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 ---------------- diff --git a/mods/ENTITIES/mobs/crafts.lua b/mods/ENTITIES/mobs/crafts.lua index e3bcadce51..cb0c9da649 100644 --- a/mods/ENTITIES/mobs/crafts.lua +++ b/mods/ENTITIES/mobs/crafts.lua @@ -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, diff --git a/mods/ENTITIES/mobs_mc/ender_dragon.lua b/mods/ENTITIES/mobs_mc/ender_dragon.lua index 552dffd572..183b078111 100644 --- a/mods/ENTITIES/mobs_mc/ender_dragon.lua +++ b/mods/ENTITIES/mobs_mc/ender_dragon.lua @@ -93,6 +93,8 @@ mobs:register_mob("mobs_mc:enderdragon", { run_start = 0, run_end = 20, }, blood_amount = 0, + + ignores_nametag = true, })