1
0
Fork 0

Handle item naming of banners

This commit is contained in:
Wuzzy 2018-02-02 05:07:58 +01:00
parent 87ef954409
commit 06c9b2c3f6
2 changed files with 33 additions and 8 deletions

View File

@ -218,7 +218,11 @@ for colorid, colortab in pairs(mcl_banners.colors) do
table.remove(layers)
imeta:set_string("layers", minetest.serialize(layers))
local newdesc = mcl_banners.make_advanced_banner_description(itemstack:get_definition().description, layers)
imeta:set_string("description", newdesc)
local mname = imeta:get_string("name")
-- Don't change description if item has a name
if mname == "" then
imeta:set_string("description", newdesc)
end
end
-- Washing off reduces the water level by 1.
@ -272,6 +276,10 @@ for colorid, colortab in pairs(mcl_banners.colors) do
local layers_raw = imeta:get_string("layers")
local layers = minetest.deserialize(layers_raw)
banner:get_luaentity():_set_textures(colorid, layers)
local mname = imeta:get_string("name")
if mname ~= nil and mname ~= "" then
banner:get_luaentity()._item_name = mname
end
-- Set rotation
local final_yaw
@ -336,7 +344,7 @@ local entity_standing = {
-- pattern: name of pattern (see list above)
get_staticdata = function(self)
local out = { _base_color = self._base_color, _layers = self._layers }
local out = { _base_color = self._base_color, _layers = self._layers, _name = self._name }
return minetest.serialize(out)
end,
on_activate = function(self, staticdata)
@ -344,6 +352,7 @@ local entity_standing = {
local inp = minetest.deserialize(staticdata)
self._base_color = inp._base_color
self._layers = inp._layers
self._name = inp._name
self.object:set_properties({
textures = make_banner_texture(self._base_color, self._layers),
})
@ -363,7 +372,12 @@ local entity_standing = {
local banner = ItemStack("mcl_banners:banner_item_"..mcl_banners.colors[self._base_color][1])
local meta = banner:get_meta()
meta:set_string("layers", minetest.serialize(self._layers))
meta:set_string("description", mcl_banners.make_advanced_banner_description(banner:get_definition().description, self._layers))
if self._item_name ~= nil and self._item_name ~= "" then
meta:set_string("description", self._item_name)
meta:set_string("name", self._item_name)
else
meta:set_string("description", mcl_banners.make_advanced_banner_description(banner:get_definition().description, self._layers))
end
minetest.add_item(pos, banner)
end

View File

@ -339,16 +339,18 @@ local banner_pattern_craft = function(itemstack, player, old_craft_grid, craft_i
-- For copying to be allowed, one banner has to have no layers while the other one has at least 1 layer.
-- The banner with layers will be used as a source.
local src_banner, src_layers_raw, src_desc, src_index
local src_banner, src_layers_raw, src_desc, src_index, src_has_name
if #b1layers == 0 and #b2layers > 0 then
src_banner = banner2
src_layers_raw = b2layers_raw
src_desc = b2meta:get_string("description")
src_has_no_name = b2meta:get_string("name") == ""
src_index = banner2_index
elseif #b2layers == 0 and #b1layers > 0 then
src_banner = banner
src_layers_raw = b1layers_raw
src_desc = b1meta:get_string("description")
src_has_no_name = b1meta:get_string("name") == ""
src_index = banner_index
else
return ItemStack("")
@ -357,7 +359,10 @@ local banner_pattern_craft = function(itemstack, player, old_craft_grid, craft_i
-- Set output metadata
local imeta = itemstack:get_meta()
imeta:set_string("layers", src_layers_raw)
imeta:set_string("description", src_desc)
-- Keep description if banner has a name
if src_has_no_name then
imeta:set_string("description", src_desc)
end
if not craft_predict then
-- Don't destroy source banner so this recipe is a true copy
@ -461,9 +466,15 @@ local banner_pattern_craft = function(itemstack, player, old_craft_grid, craft_i
local imeta = itemstack:get_meta()
imeta:set_string("layers", minetest.serialize(layers))
local odesc = itemstack:get_definition().description
local description = mcl_banners.make_advanced_banner_description(odesc, layers)
imeta:set_string("description", description)
local mname = ometa:get_string("name")
-- Only change description if banner does not have a name
if mname == "" then
local odesc = itemstack:get_definition().description
local description = mcl_banners.make_advanced_banner_description(odesc, layers)
imeta:set_string("description", description)
else
imeta:set_string("description", mname)
end
return itemstack
end