mirror of
https://git.minetest.land/Mineclonia/Mineclonia.git
synced 2024-11-28 05:03:03 +00:00
Use color for named items
This commit is contained in:
parent
8ff92fcb7f
commit
197afa664b
3 changed files with 16 additions and 9 deletions
|
@ -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
|
||||||
|
-- Empty name
|
||||||
|
if name_item:get_definition()._mcl_generate_description then
|
||||||
-- _mcl_generate_description(itemstack): If defined, set custom item description of itemstack.
|
-- _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)
|
name_item:get_definition()._mcl_generate_description(name_item)
|
||||||
else
|
else
|
||||||
-- Set description
|
-- Otherwise, just clear description
|
||||||
meta:set_string("description", new_name)
|
meta:set_string("description", "")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- 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
|
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)
|
||||||
|
|
|
@ -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))
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue