mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-16 16:11:06 +01:00
Handle item naming of banners
This commit is contained in:
parent
87ef954409
commit
06c9b2c3f6
2 changed files with 33 additions and 8 deletions
|
@ -218,7 +218,11 @@ for colorid, colortab in pairs(mcl_banners.colors) do
|
||||||
table.remove(layers)
|
table.remove(layers)
|
||||||
imeta:set_string("layers", minetest.serialize(layers))
|
imeta:set_string("layers", minetest.serialize(layers))
|
||||||
local newdesc = mcl_banners.make_advanced_banner_description(itemstack:get_definition().description, 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
|
end
|
||||||
|
|
||||||
-- Washing off reduces the water level by 1.
|
-- 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_raw = imeta:get_string("layers")
|
||||||
local layers = minetest.deserialize(layers_raw)
|
local layers = minetest.deserialize(layers_raw)
|
||||||
banner:get_luaentity():_set_textures(colorid, layers)
|
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
|
-- Set rotation
|
||||||
local final_yaw
|
local final_yaw
|
||||||
|
@ -336,7 +344,7 @@ local entity_standing = {
|
||||||
-- pattern: name of pattern (see list above)
|
-- pattern: name of pattern (see list above)
|
||||||
|
|
||||||
get_staticdata = function(self)
|
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)
|
return minetest.serialize(out)
|
||||||
end,
|
end,
|
||||||
on_activate = function(self, staticdata)
|
on_activate = function(self, staticdata)
|
||||||
|
@ -344,6 +352,7 @@ local entity_standing = {
|
||||||
local inp = minetest.deserialize(staticdata)
|
local inp = minetest.deserialize(staticdata)
|
||||||
self._base_color = inp._base_color
|
self._base_color = inp._base_color
|
||||||
self._layers = inp._layers
|
self._layers = inp._layers
|
||||||
|
self._name = inp._name
|
||||||
self.object:set_properties({
|
self.object:set_properties({
|
||||||
textures = make_banner_texture(self._base_color, self._layers),
|
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 banner = ItemStack("mcl_banners:banner_item_"..mcl_banners.colors[self._base_color][1])
|
||||||
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))
|
||||||
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)
|
minetest.add_item(pos, banner)
|
||||||
end
|
end
|
||||||
|
|
|
@ -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.
|
-- 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.
|
-- 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
|
if #b1layers == 0 and #b2layers > 0 then
|
||||||
src_banner = banner2
|
src_banner = banner2
|
||||||
src_layers_raw = b2layers_raw
|
src_layers_raw = b2layers_raw
|
||||||
src_desc = b2meta:get_string("description")
|
src_desc = b2meta:get_string("description")
|
||||||
|
src_has_no_name = b2meta:get_string("name") == ""
|
||||||
src_index = banner2_index
|
src_index = banner2_index
|
||||||
elseif #b2layers == 0 and #b1layers > 0 then
|
elseif #b2layers == 0 and #b1layers > 0 then
|
||||||
src_banner = banner
|
src_banner = banner
|
||||||
src_layers_raw = b1layers_raw
|
src_layers_raw = b1layers_raw
|
||||||
src_desc = b1meta:get_string("description")
|
src_desc = b1meta:get_string("description")
|
||||||
|
src_has_no_name = b1meta:get_string("name") == ""
|
||||||
src_index = banner_index
|
src_index = banner_index
|
||||||
else
|
else
|
||||||
return ItemStack("")
|
return ItemStack("")
|
||||||
|
@ -357,7 +359,10 @@ local banner_pattern_craft = function(itemstack, player, old_craft_grid, craft_i
|
||||||
-- Set output metadata
|
-- Set output metadata
|
||||||
local imeta = itemstack:get_meta()
|
local imeta = itemstack:get_meta()
|
||||||
imeta:set_string("layers", src_layers_raw)
|
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
|
if not craft_predict then
|
||||||
-- Don't destroy source banner so this recipe is a true copy
|
-- 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()
|
local imeta = itemstack:get_meta()
|
||||||
imeta:set_string("layers", minetest.serialize(layers))
|
imeta:set_string("layers", minetest.serialize(layers))
|
||||||
|
|
||||||
local odesc = itemstack:get_definition().description
|
local mname = ometa:get_string("name")
|
||||||
local description = mcl_banners.make_advanced_banner_description(odesc, layers)
|
-- Only change description if banner does not have a name
|
||||||
imeta:set_string("description", description)
|
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
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue