Fix restore of banner desc after anvil rename
This commit is contained in:
parent
a7f0d8c82c
commit
2c0eee27fc
8
API.md
8
API.md
|
@ -9,6 +9,14 @@ Mods mods in MineClone 2 follow a simple naming convention: Mods with the prefix
|
|||
## Adding items
|
||||
### Special fields
|
||||
|
||||
Items can have these fields:
|
||||
* `_mcl_generate_description(itemstack)`: Required for any items which manipulate their
|
||||
description in any way. This function takes an itemstack of its own type and must set
|
||||
the proper advanced description for this itemstack. If you don't do this, anvils will
|
||||
fail at properly restoring the description when their custom name gets cleared at an
|
||||
anvil.
|
||||
See `mcl_banners` for an example.
|
||||
|
||||
All nodes can have these fields:
|
||||
|
||||
* `_mcl_hardness`: Hardness of the block, ranges from 0 to infinity (represented by -1). Determines digging times. Default: 0
|
||||
|
|
|
@ -129,8 +129,16 @@ local function update_anvil_slots(meta)
|
|||
-- Don't rename if names are identical
|
||||
if new_name ~= old_name then
|
||||
-- Rename item
|
||||
meta:set_string("description", new_name)
|
||||
-- Double-save the name internally, too
|
||||
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)
|
||||
else
|
||||
-- Set description
|
||||
meta:set_string("description", new_name)
|
||||
end
|
||||
-- Save the raw name internally, too
|
||||
meta:set_string("name", new_name)
|
||||
new_output = name_item
|
||||
elseif just_rename then
|
||||
|
|
|
@ -302,6 +302,19 @@ for colorid, colortab in pairs(mcl_banners.colors) do
|
|||
|
||||
return itemstack
|
||||
end,
|
||||
|
||||
_mcl_generate_description = function(itemstack)
|
||||
local meta = itemstack:get_meta()
|
||||
local layers_raw = meta:get_string("layers")
|
||||
if not layers_raw then
|
||||
return nil
|
||||
end
|
||||
local layers = minetest.deserialize(layers_raw)
|
||||
local desc = itemstack:get_definition().description
|
||||
local newdesc = mcl_banners.make_advanced_banner_description(desc, layers)
|
||||
meta:set_string("description", newdesc)
|
||||
return newdesc
|
||||
end,
|
||||
})
|
||||
|
||||
if minetest.get_modpath("mcl_core") and minetest.get_modpath("mcl_wool") then
|
||||
|
|
Loading…
Reference in New Issue