items/mcl_banners: make previews items compatible with side preview

The newly-added preview items (#40) didn't play nice with the side
preview image, mostly because the "layers" metadata wasn't generated,
and they didn't record the base color of the actual banner being crafted.

This commit re-adds that (and other) metadata.
This commit is contained in:
E 2021-05-02 00:00:14 -04:00
parent cb4173ac9e
commit c29d725755
2 changed files with 9 additions and 5 deletions

View File

@ -178,7 +178,7 @@ function mcl_banners.get_overlay(istk)
if not layers_raw or layers_raw == "" then
return
end
local basec = istk:get_definition()._base_color
local basec = imeta:get("fake_base") or istk:get_definition()._base_color
if not basec then
basec="unicolor_white"
end

View File

@ -472,11 +472,12 @@ 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 idef=itemstack:get_definition()
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 odesc = idef.description
local description = mcl_banners.make_advanced_banner_description(odesc, layers)
imeta:set_string("description", description)
else
@ -487,10 +488,13 @@ local banner_pattern_craft = function(itemstack, player, old_craft_grid, craft_i
if craft_predict then
local itemid_prefix = "mcl_banners:banner_preview"
local coloritemid = dye_to_itemid_mapping[dye]
return ItemStack(itemid_prefix .. "_" .. matching_pattern .. "_" .. coloritemid)
else
return itemstack
local is=ItemStack(itemid_prefix .. "_" .. matching_pattern .. "_" .. coloritemid)
local im=is:get_meta()
im:from_table(imeta:to_table())
im:set_string("fake_base", idef._base_color)
return is
end
return itemstack
end
minetest.register_craft_predict(function(itemstack, player, old_craft_grid, craft_inv)