From 197afa664bc031f102135564cc3020fb5fe48820 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sun, 4 Feb 2018 06:36:44 +0100 Subject: [PATCH] Use color for named items --- mods/ITEMS/mcl_anvils/init.lua | 20 +++++++++++++------- mods/ITEMS/mcl_banners/init.lua | 3 ++- mods/ITEMS/mcl_banners/patterncraft.lua | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/mods/ITEMS/mcl_anvils/init.lua b/mods/ITEMS/mcl_anvils/init.lua index 64ef7a4521..37d0a1fc9e 100644 --- a/mods/ITEMS/mcl_anvils/init.lua +++ b/mods/ITEMS/mcl_anvils/init.lua @@ -2,6 +2,7 @@ local MAX_NAME_LENGTH = 30 local MAX_WEAR = 65535 local SAME_TOOL_REPAIR_BOOST = math.ceil(MAX_WEAR * 0.12) -- 12% local MATERIAL_TOOL_REPAIR_BOOST = math.ceil(MAX_WEAR * 0.25) -- 25% +local NAME_COLOR = "#FFFF4C" local function get_anvil_formspec(set_name) if not set_name then @@ -129,14 +130,19 @@ local function update_anvil_slots(meta) -- Don't rename if names are identical if new_name ~= old_name then -- Rename item - if new_name == "" and name_item:get_definition()._mcl_generate_description then - -- _mcl_generate_description(itemstack): If defined, set custom item description of itemstack. - -- This function should be defined for items with an advanced description. - -- See mcl_banners for an example. - name_item:get_definition()._mcl_generate_description(name_item) + if new_name == "" then + -- Empty name + if name_item:get_definition()._mcl_generate_description then + -- _mcl_generate_description(itemstack): If defined, set custom item description of itemstack. + name_item:get_definition()._mcl_generate_description(name_item) + else + -- Otherwise, just clear description + meta:set_string("description", "") + end else - -- Set description - meta:set_string("description", new_name) + -- Custom name set. Colorize it! + -- This makes the name visually different from unnamed items + meta:set_string("description", core.colorize(NAME_COLOR, new_name)) end -- Save the raw name internally, too meta:set_string("name", new_name) diff --git a/mods/ITEMS/mcl_banners/init.lua b/mods/ITEMS/mcl_banners/init.lua index bf5f153132..6990632623 100644 --- a/mods/ITEMS/mcl_banners/init.lua +++ b/mods/ITEMS/mcl_banners/init.lua @@ -279,6 +279,7 @@ for colorid, colortab in pairs(mcl_banners.colors) do local mname = imeta:get_string("name") if mname ~= nil and mname ~= "" then banner:get_luaentity()._item_name = mname + banner:get_luaentity()._item_description = imeta:get_string("description") end -- Set rotation @@ -386,7 +387,7 @@ local entity_standing = { local meta = banner:get_meta() meta:set_string("layers", minetest.serialize(self._layers)) if self._item_name ~= nil and self._item_name ~= "" then - meta:set_string("description", self._item_name) + meta:set_string("description", self._item_description) meta:set_string("name", self._item_name) else meta:set_string("description", mcl_banners.make_advanced_banner_description(banner:get_definition().description, self._layers)) diff --git a/mods/ITEMS/mcl_banners/patterncraft.lua b/mods/ITEMS/mcl_banners/patterncraft.lua index ae222b0b52..8d202c78c4 100644 --- a/mods/ITEMS/mcl_banners/patterncraft.lua +++ b/mods/ITEMS/mcl_banners/patterncraft.lua @@ -471,7 +471,7 @@ local banner_pattern_craft = function(itemstack, player, old_craft_grid, craft_i local description = mcl_banners.make_advanced_banner_description(odesc, layers) imeta:set_string("description", description) else - imeta:set_string("description", mname) + imeta:set_string("description", ometa:get_string("description")) imeta:set_string("name", mname) end return itemstack