Use color for named items

This commit is contained in:
Wuzzy 2018-02-04 06:36:44 +01:00
parent 8ff92fcb7f
commit 197afa664b
3 changed files with 16 additions and 9 deletions

View File

@ -2,6 +2,7 @@ local MAX_NAME_LENGTH = 30
local MAX_WEAR = 65535 local MAX_WEAR = 65535
local SAME_TOOL_REPAIR_BOOST = math.ceil(MAX_WEAR * 0.12) -- 12% 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 MATERIAL_TOOL_REPAIR_BOOST = math.ceil(MAX_WEAR * 0.25) -- 25%
local NAME_COLOR = "#FFFF4C"
local function get_anvil_formspec(set_name) local function get_anvil_formspec(set_name)
if not set_name then if not set_name then
@ -129,14 +130,19 @@ local function update_anvil_slots(meta)
-- Don't rename if names are identical -- Don't rename if names are identical
if new_name ~= old_name then if new_name ~= old_name then
-- Rename item -- Rename item
if new_name == "" and name_item:get_definition()._mcl_generate_description then if new_name == "" then
-- _mcl_generate_description(itemstack): If defined, set custom item description of itemstack. -- Empty name
-- This function should be defined for items with an advanced description. if name_item:get_definition()._mcl_generate_description then
-- See mcl_banners for an example. -- _mcl_generate_description(itemstack): If defined, set custom item description of itemstack.
name_item:get_definition()._mcl_generate_description(name_item) name_item:get_definition()._mcl_generate_description(name_item)
else
-- Otherwise, just clear description
meta:set_string("description", "")
end
else else
-- Set description -- Custom name set. Colorize it!
meta:set_string("description", new_name) -- This makes the name visually different from unnamed items
meta:set_string("description", core.colorize(NAME_COLOR, new_name))
end end
-- Save the raw name internally, too -- Save the raw name internally, too
meta:set_string("name", new_name) meta:set_string("name", new_name)

View File

@ -279,6 +279,7 @@ for colorid, colortab in pairs(mcl_banners.colors) do
local mname = imeta:get_string("name") local mname = imeta:get_string("name")
if mname ~= nil and mname ~= "" then if mname ~= nil and mname ~= "" then
banner:get_luaentity()._item_name = mname banner:get_luaentity()._item_name = mname
banner:get_luaentity()._item_description = imeta:get_string("description")
end end
-- Set rotation -- Set rotation
@ -386,7 +387,7 @@ local entity_standing = {
local meta = banner:get_meta() local meta = banner:get_meta()
meta:set_string("layers", minetest.serialize(self._layers)) meta:set_string("layers", minetest.serialize(self._layers))
if self._item_name ~= nil and self._item_name ~= "" then 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) meta:set_string("name", self._item_name)
else else
meta:set_string("description", mcl_banners.make_advanced_banner_description(banner:get_definition().description, self._layers)) meta:set_string("description", mcl_banners.make_advanced_banner_description(banner:get_definition().description, self._layers))

View File

@ -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) local description = mcl_banners.make_advanced_banner_description(odesc, layers)
imeta:set_string("description", description) imeta:set_string("description", description)
else else
imeta:set_string("description", mname) imeta:set_string("description", ometa:get_string("description"))
imeta:set_string("name", mname) imeta:set_string("name", mname)
end end
return itemstack return itemstack