Move item renaming to tt. This allows additional information such as enchantments to be displayed on named items

This commit is contained in:
Blue Blancmange 2021-03-22 21:50:14 +00:00
parent e9182a9506
commit 44c4999b37
2 changed files with 7 additions and 10 deletions

View file

@ -2,6 +2,7 @@ tt = {}
tt.COLOR_DEFAULT = "#d0ffd0"
tt.COLOR_DANGER = "#ffff00"
tt.COLOR_GOOD = "#00ff00"
tt.NAME_COLOR = "#FFFF4C"
-- API
tt.registered_snippets = {}
@ -63,12 +64,15 @@ tt.reload_itemstack_description = function(itemstack)
local meta = itemstack:get_meta()
if def and def._mcl_generate_description then
def._mcl_generate_description(itemstack)
elseif should_change(itemstring, def) and meta:get_string("name") == "" then
elseif should_change(itemstring, def) then
local toolcaps
if def.tool_capabilities then
toolcaps = itemstack:get_tool_capabilities()
end
local orig_desc = def._tt_original_description or def.description
if meta:get_string("name") ~= "" then
orig_desc = minetest.colorize(tt.NAME_COLOR, meta:get_string("name"))
end
local desc = apply_snippets(orig_desc, itemstring, toolcaps or def.tool_capabilities, itemstack)
if desc ~= orig_desc then
meta:set_string("description", desc)

View file

@ -9,7 +9,6 @@ local MATERIAL_TOOL_REPAIR_BOOST = {
math.ceil(MAX_WEAR * 0.75), -- 75%
MAX_WEAR, -- 100%
}
local NAME_COLOR = "#FFFF4C"
local function get_anvil_formspec(set_name)
if not set_name then
@ -172,14 +171,8 @@ local function update_anvil_slots(meta)
if new_name ~= old_name then
-- Save the raw name internally
meta:set_string("name", new_name)
-- Rename item
if new_name == "" then
tt.reload_itemstack_description(name_item)
else
-- Custom name set. Colorize it!
-- This makes the name visually different from unnamed items
meta:set_string("description", minetest.colorize(NAME_COLOR, new_name))
end
-- Rename item handled by tt
tt.reload_itemstack_description(name_item)
new_output = name_item
elseif just_rename then
new_output = ""