Force same dye color on banner crafting

This commit is contained in:
Wuzzy 2017-07-28 18:12:16 +02:00
parent b46ac0658e
commit f566241bb6
1 changed files with 27 additions and 11 deletions

View File

@ -195,16 +195,25 @@ minetest.register_craft_predict(function(itemstack, player, old_craft_grid, craf
return return
end end
local original local banner
local dye
local index local index
for i = 1, player:get_inventory():get_size("craft") do for i = 1, player:get_inventory():get_size("craft") do
if minetest.get_item_group(old_craft_grid[i]:get_name(), "banner") == 1 then local itemname = old_craft_grid[i]:get_name()
original = old_craft_grid[i] if minetest.get_item_group(itemname, "banner") == 1 then
banner = old_craft_grid[i]
index = i index = i
-- Check if all dyes are equal
elseif minetest.get_item_group(itemname, "dye") == 1 then
if dye == nil then
dye = itemname
elseif itemname ~= dye then
return ItemStack("")
end
end end
end end
if not original then if not banner then
return return ItemStack("")
end end
local imeta = itemstack:get_meta() local imeta = itemstack:get_meta()
@ -219,27 +228,34 @@ minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv
return return
end end
local original local banner, dye
local index local index
for i = 1, player:get_inventory():get_size("craft") do for i = 1, player:get_inventory():get_size("craft") do
local itemname = old_craft_grid[i]:get_name() local itemname = old_craft_grid[i]:get_name()
if minetest.get_item_group(itemname, "banner") == 1 then if minetest.get_item_group(itemname, "banner") == 1 then
original = old_craft_grid[i] banner = old_craft_grid[i]
index = i index = i
-- Check if all dyes are equal
elseif minetest.get_item_group(itemname, "dye") == 1 then
if dye == nil then
dye = itemname
elseif itemname ~= dye then
return ItemStack("")
end
end end
end end
if not original then if not banner then
return return ItemStack("")
end end
local ometa = original:get_meta() local ometa = banner:get_meta()
local layers_raw = ometa:get_string("layers") local layers_raw = ometa:get_string("layers")
local layers = minetest.deserialize(layers_raw) local layers = minetest.deserialize(layers_raw)
if type(layers) ~= "table" then if type(layers) ~= "table" then
layers = {} layers = {}
end end
table.insert(layers, {pattern="circle", color = "unicolor_yellow"}) table.insert(layers, {pattern="circle", color="unicolor_yellow"})
local imeta = itemstack:get_meta() local imeta = itemstack:get_meta()
imeta:set_string("layers", minetest.serialize(layers)) imeta:set_string("layers", minetest.serialize(layers))