1
0
Fork 0

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

View File

@ -9,7 +9,6 @@ local MATERIAL_TOOL_REPAIR_BOOST = {
math.ceil(MAX_WEAR * 0.75), -- 75% math.ceil(MAX_WEAR * 0.75), -- 75%
MAX_WEAR, -- 100% MAX_WEAR, -- 100%
} }
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
@ -172,14 +171,8 @@ local function update_anvil_slots(meta)
if new_name ~= old_name then if new_name ~= old_name then
-- Save the raw name internally -- Save the raw name internally
meta:set_string("name", new_name) meta:set_string("name", new_name)
-- Rename item -- Rename item handled by tt
if new_name == "" then
tt.reload_itemstack_description(name_item) 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
new_output = name_item new_output = name_item
elseif just_rename then elseif just_rename then
new_output = "" new_output = ""