2017-07-28 17:23:13 +02:00
|
|
|
-- List of patterns with crafting rules
|
|
|
|
|
2017-07-28 17:41:04 +02:00
|
|
|
local d = "group:dye" -- dye
|
2017-07-28 17:23:13 +02:00
|
|
|
local e = "" -- empty slot (one of them must contain the banner)
|
2017-07-28 14:54:34 +02:00
|
|
|
local patterns = {
|
2017-07-28 17:23:13 +02:00
|
|
|
["border"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Bordure",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ d, d, d },
|
|
|
|
{ d, e, d },
|
|
|
|
{ d, d, d },
|
|
|
|
},
|
|
|
|
["bricks"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Bricks",
|
2017-07-28 17:23:13 +02:00
|
|
|
type = "shapeless",
|
2017-07-28 17:41:04 +02:00
|
|
|
{ e, "mcl_core:brick_block", d },
|
2017-07-28 17:23:13 +02:00
|
|
|
},
|
|
|
|
["circle"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Circle",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ e, e, e },
|
|
|
|
{ e, d, e },
|
|
|
|
{ e, e, e },
|
|
|
|
},
|
|
|
|
["creeper"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Creeper Charge",
|
2017-07-28 17:23:13 +02:00
|
|
|
type = "shapeless",
|
2017-07-28 17:41:04 +02:00
|
|
|
{ e, "mcl_heads:creeper", d },
|
2017-07-28 17:23:13 +02:00
|
|
|
},
|
|
|
|
["cross"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Saltire",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ d, e, d },
|
|
|
|
{ e, d, e },
|
|
|
|
{ d, e, d },
|
|
|
|
},
|
|
|
|
["curly_border"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Intented Bordure",
|
2017-07-28 17:41:04 +02:00
|
|
|
type = "shapeless",
|
|
|
|
{ e, "mcl_core:vine", d },
|
2017-07-28 17:23:13 +02:00
|
|
|
},
|
|
|
|
["diagonal_left"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Inverted Per Bend",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ e, e, e },
|
|
|
|
{ d, e, e },
|
|
|
|
{ d, d, e },
|
|
|
|
},
|
|
|
|
["diagonal_right"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Inverted Per Bend Sinister",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ e, e, e },
|
|
|
|
{ e, e, d },
|
|
|
|
{ e, d, d },
|
|
|
|
},
|
|
|
|
["diagonal_up_left"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Per Bend",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ e, d, d },
|
|
|
|
{ e, e, d },
|
|
|
|
{ e, e, e },
|
|
|
|
},
|
|
|
|
["diagonal_up_right"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Per Bend Sinister",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ d, d, e },
|
|
|
|
{ d, e, e },
|
|
|
|
{ e, e, e },
|
|
|
|
},
|
|
|
|
["flower"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Flower Charge",
|
2017-07-28 17:23:13 +02:00
|
|
|
type = "shapeless",
|
2017-07-28 17:41:04 +02:00
|
|
|
{ e, "mcl_flowers:oxeye_daisy", d },
|
2017-07-28 17:23:13 +02:00
|
|
|
},
|
|
|
|
["gradient"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Gradient",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ d, e, d },
|
|
|
|
{ e, d, e },
|
|
|
|
{ e, d, e },
|
|
|
|
},
|
|
|
|
["gradient_up"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Base Gradient",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ e, d, e },
|
|
|
|
{ e, d, e },
|
|
|
|
{ d, e, d },
|
|
|
|
},
|
|
|
|
["half_horizontal_bottom"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Inverted Per Fess",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ e, e, e },
|
|
|
|
{ d, d, d },
|
|
|
|
{ d, d, d },
|
|
|
|
},
|
|
|
|
["half_horizontal"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Per Fess",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ d, d, d },
|
|
|
|
{ d, d, d },
|
|
|
|
{ e, e, e },
|
|
|
|
},
|
|
|
|
["half_vertical"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Per Pale",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ d, d, e },
|
|
|
|
{ d, d, e },
|
|
|
|
{ d, d, e },
|
|
|
|
},
|
|
|
|
["half_vertical_right"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Inverted Per Pale",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ e, d, d },
|
|
|
|
{ e, d, d },
|
|
|
|
{ e, d, d },
|
|
|
|
},
|
|
|
|
["thing"] = {
|
2017-07-28 23:15:03 +02:00
|
|
|
-- Symbol used for the “Thing”: U+1F65D 🙝
|
|
|
|
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Thing",
|
2017-07-28 17:23:13 +02:00
|
|
|
type = "shapeless",
|
2017-07-28 17:41:04 +02:00
|
|
|
-- TODO: Replace with enchanted golden apple
|
|
|
|
{ e, "mcl_core:apple_gold", d },
|
2017-07-28 17:23:13 +02:00
|
|
|
},
|
|
|
|
["rhombus"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Lozenge",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ e, d, e },
|
|
|
|
{ d, e, d },
|
|
|
|
{ e, d, e },
|
|
|
|
},
|
|
|
|
["skull"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Skull Charge",
|
2017-07-28 17:23:13 +02:00
|
|
|
type = "shapeless",
|
2017-07-28 17:41:04 +02:00
|
|
|
{ e, "mcl_heads:wither_skeleton", d },
|
2017-07-28 17:23:13 +02:00
|
|
|
},
|
|
|
|
["small_stripes"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Paly",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ d, e, d },
|
|
|
|
{ d, e, d },
|
|
|
|
{ e, e, e },
|
|
|
|
},
|
|
|
|
["square_bottom_left"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Base Dexter Canton",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ e, e, e },
|
|
|
|
{ e, e, e },
|
|
|
|
{ d, e, e },
|
|
|
|
},
|
|
|
|
["square_bottom_right"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Base Sinister Canton",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ e, e, e },
|
|
|
|
{ e, e, e },
|
|
|
|
{ e, e, d },
|
|
|
|
},
|
|
|
|
["square_top_left"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Chief Dexter Canton",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ d, e, e },
|
|
|
|
{ e, e, e },
|
|
|
|
{ e, e, e },
|
|
|
|
},
|
|
|
|
["square_top_right"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Chief Sinister Canton",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ e, e, d },
|
|
|
|
{ e, e, e },
|
|
|
|
{ e, e, e },
|
|
|
|
},
|
|
|
|
["straight_cross"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Cross",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ e, d, e },
|
|
|
|
{ d, d, d },
|
|
|
|
{ e, d, e },
|
|
|
|
},
|
|
|
|
["stripe_bottom"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Base",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ e, e, e },
|
|
|
|
{ e, e, e },
|
|
|
|
{ d, d, d },
|
|
|
|
},
|
|
|
|
["stripe_center"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Fess",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ e, e, e },
|
|
|
|
{ d, d, d },
|
|
|
|
{ e, e, e },
|
|
|
|
},
|
|
|
|
["stripe_downleft"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Bend Sinister",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ e, e, d },
|
|
|
|
{ e, d, e },
|
|
|
|
{ d, e, e },
|
|
|
|
},
|
|
|
|
["stripe_downright"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Bend",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ d, e, e },
|
|
|
|
{ e, d, e },
|
|
|
|
{ e, e, d },
|
|
|
|
},
|
|
|
|
["stripe_left"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Pale Dexter",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ d, e, e },
|
|
|
|
{ d, e, e },
|
|
|
|
{ d, e, e },
|
|
|
|
},
|
|
|
|
["stripe_middle"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Pale",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ e, d, e },
|
|
|
|
{ e, d, e },
|
|
|
|
{ e, d, e },
|
|
|
|
},
|
|
|
|
["stripe_right"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Pale Sinister",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ e, e, d },
|
|
|
|
{ e, e, d },
|
|
|
|
{ e, e, d },
|
|
|
|
},
|
|
|
|
["stripe_top"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Chief",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ d, d, d },
|
|
|
|
{ e, e, e },
|
|
|
|
{ e, e, e },
|
|
|
|
},
|
|
|
|
["triangle_bottom"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Chevron",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ e, e, e },
|
|
|
|
{ e, d, e },
|
|
|
|
{ d, e, d },
|
|
|
|
},
|
2017-07-28 23:12:40 +02:00
|
|
|
["triangle_top"] = {
|
|
|
|
name = "%s Inverted Chevron",
|
|
|
|
{ d, e, d },
|
|
|
|
{ e, d, e },
|
|
|
|
{ e, e, e },
|
|
|
|
},
|
2017-07-28 17:23:13 +02:00
|
|
|
["triangles_bottom"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Base Indented",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ e, e, e },
|
|
|
|
{ d, e, d },
|
|
|
|
{ e, d, e },
|
|
|
|
},
|
|
|
|
["triangles_top"] = {
|
2017-07-28 23:12:40 +02:00
|
|
|
name = "%s Chief Indented",
|
2017-07-28 17:23:13 +02:00
|
|
|
{ e, d, e },
|
|
|
|
{ d, e, d },
|
|
|
|
{ e, e, e },
|
|
|
|
},
|
2017-07-28 14:54:34 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 22:46:39 +02:00
|
|
|
-- Number of maximum lines in the descriptions for the banner layers.
|
|
|
|
-- To avoid huge tooltips.
|
|
|
|
local max_layer_lines = 6
|
|
|
|
|
|
|
|
-- Create a banner description containing all the layer names
|
|
|
|
local make_advanced_banner_description = function(description, layers)
|
|
|
|
if layers == nil or #layers == 0 then
|
|
|
|
-- No layers, revert to default
|
|
|
|
return ""
|
|
|
|
else
|
|
|
|
local layerstrings = {}
|
|
|
|
for l=1, #layers do
|
2017-07-28 23:12:40 +02:00
|
|
|
-- Prevent excess length description
|
2017-07-28 22:46:39 +02:00
|
|
|
if l > max_layer_lines then
|
|
|
|
break
|
|
|
|
end
|
2017-07-28 23:12:40 +02:00
|
|
|
-- Layer text line.
|
|
|
|
local color = mcl_banners.colors[layers[l].color][6]
|
|
|
|
local pattern_name = patterns[layers[l].pattern].name
|
|
|
|
-- The pattern name is a format string (e.g. “%s Base”)
|
|
|
|
table.insert(layerstrings, string.format(pattern_name, color))
|
2017-07-28 22:46:39 +02:00
|
|
|
end
|
2017-07-28 23:12:40 +02:00
|
|
|
-- Warn about missing information
|
2017-07-28 22:46:39 +02:00
|
|
|
if #layers == max_layer_lines + 1 then
|
|
|
|
table.insert(layerstrings, "And one addional layer")
|
|
|
|
elseif #layers > max_layer_lines + 1 then
|
|
|
|
table.insert(layerstrings, string.format("And %d addional layers", #layers - max_layer_lines))
|
|
|
|
end
|
2017-07-28 23:12:40 +02:00
|
|
|
|
|
|
|
-- Final string concatenations: Just a list of strings
|
2017-07-28 22:46:39 +02:00
|
|
|
local append = table.concat(layerstrings, "\n")
|
2017-07-28 23:12:40 +02:00
|
|
|
description = description .. "\n" .. core.colorize("#8F8F8F", append)
|
|
|
|
return description
|
2017-07-28 22:46:39 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-28 22:23:21 +02:00
|
|
|
-- This is for handling all those complex pattern crafting recipes
|
2017-07-28 22:26:37 +02:00
|
|
|
local banner_pattern_craft = function(itemstack, player, old_craft_grid, craft_inv)
|
2017-07-28 14:54:34 +02:00
|
|
|
if minetest.get_item_group(itemstack:get_name(), "banner") ~= 1 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-07-28 18:12:16 +02:00
|
|
|
local banner, dye
|
2017-07-28 22:23:21 +02:00
|
|
|
local banner_index
|
2017-07-28 14:54:34 +02:00
|
|
|
for i = 1, player:get_inventory():get_size("craft") do
|
|
|
|
local itemname = old_craft_grid[i]:get_name()
|
|
|
|
if minetest.get_item_group(itemname, "banner") == 1 then
|
2017-07-28 18:12:16 +02:00
|
|
|
banner = old_craft_grid[i]
|
2017-07-28 22:23:21 +02:00
|
|
|
banner_index = i
|
2017-07-28 18:12:16 +02:00
|
|
|
-- 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
|
2017-07-28 14:54:34 +02:00
|
|
|
end
|
|
|
|
end
|
2017-07-28 18:12:16 +02:00
|
|
|
if not banner then
|
|
|
|
return ItemStack("")
|
2017-07-28 14:54:34 +02:00
|
|
|
end
|
|
|
|
|
2017-07-28 22:23:21 +02:00
|
|
|
-- Get old layers
|
2017-07-28 18:12:16 +02:00
|
|
|
local ometa = banner:get_meta()
|
2017-07-28 14:54:34 +02:00
|
|
|
local layers_raw = ometa:get_string("layers")
|
|
|
|
local layers = minetest.deserialize(layers_raw)
|
|
|
|
if type(layers) ~= "table" then
|
|
|
|
layers = {}
|
|
|
|
end
|
|
|
|
|
2017-07-28 22:23:21 +02:00
|
|
|
local matching_pattern
|
|
|
|
local max_i = player:get_inventory():get_size("craft")
|
|
|
|
-- Find the matching pattern
|
|
|
|
for pattern_name, pattern in pairs(patterns) do
|
|
|
|
-- Shaped / fixed
|
|
|
|
if pattern.type == nil then
|
|
|
|
local pattern_ok = true
|
|
|
|
local inv_i = 1
|
|
|
|
-- This complex code just iterates through the pattern slots one-by-one and compares them with the pattern
|
|
|
|
for p=1, #pattern do
|
|
|
|
local row = pattern[p]
|
|
|
|
if inv_i > max_i then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
for r=1, #row do
|
|
|
|
local itemname = old_craft_grid[inv_i]:get_name()
|
|
|
|
local pitem = row[r]
|
|
|
|
if (pitem == d and minetest.get_item_group(itemname, "dye") == 0) or (pitem == e and itemname ~= e and inv_i ~= banner_index) then
|
|
|
|
pattern_ok = false
|
|
|
|
break
|
|
|
|
else
|
|
|
|
end
|
|
|
|
inv_i = inv_i + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- Everything matched! We found our pattern!
|
|
|
|
if pattern_ok then
|
|
|
|
matching_pattern = pattern_name
|
|
|
|
break
|
|
|
|
end
|
|
|
|
|
|
|
|
elseif pattern.type == "shapeless" then
|
|
|
|
-- TODO
|
|
|
|
end
|
|
|
|
|
|
|
|
if matching_pattern then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not matching_pattern then
|
|
|
|
return ItemStack("")
|
|
|
|
end
|
|
|
|
|
2017-07-28 22:46:39 +02:00
|
|
|
-- Add the new layer and update other metadata
|
2017-07-28 22:23:21 +02:00
|
|
|
table.insert(layers, {pattern=matching_pattern, color="unicolor_yellow"})
|
2017-07-28 14:54:34 +02:00
|
|
|
|
|
|
|
local imeta = itemstack:get_meta()
|
|
|
|
imeta:set_string("layers", minetest.serialize(layers))
|
|
|
|
|
2017-07-28 22:46:39 +02:00
|
|
|
local odesc = itemstack:get_definition().description
|
|
|
|
local description = make_advanced_banner_description(odesc, layers)
|
|
|
|
imeta:set_string("description", description)
|
2017-07-28 14:54:34 +02:00
|
|
|
return itemstack
|
2017-07-28 22:26:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_craft_predict(banner_pattern_craft)
|
|
|
|
minetest.register_on_craft(banner_pattern_craft)
|
|
|
|
|
2017-07-28 14:54:34 +02:00
|
|
|
|
2017-07-28 17:23:13 +02:00
|
|
|
-- Register crafting recipes for all the patterns
|
|
|
|
for pattern_name, pattern in pairs(patterns) do
|
2017-07-28 17:41:04 +02:00
|
|
|
-- Shaped and fixed recipes
|
2017-07-28 17:23:13 +02:00
|
|
|
if pattern.type == nil then
|
|
|
|
for colorid, colortab in pairs(mcl_banners.colors) do
|
|
|
|
local banner = "mcl_banners:banner_item_"..colortab[1]
|
|
|
|
local bannered = false
|
|
|
|
local recipe = {}
|
|
|
|
for row_id=1, #pattern do
|
|
|
|
local row = pattern[row_id]
|
|
|
|
local newrow = {}
|
|
|
|
for r=1, #row do
|
2017-07-28 17:41:04 +02:00
|
|
|
if row[r] == e and not bannered then
|
2017-07-28 17:23:13 +02:00
|
|
|
newrow[r] = banner
|
|
|
|
bannered = true
|
|
|
|
else
|
|
|
|
newrow[r] = row[r]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
table.insert(recipe, newrow)
|
|
|
|
end
|
|
|
|
minetest.register_craft({
|
2017-07-28 17:41:04 +02:00
|
|
|
output = banner,
|
2017-07-28 17:23:13 +02:00
|
|
|
recipe = recipe,
|
|
|
|
})
|
|
|
|
end
|
2017-07-28 17:41:04 +02:00
|
|
|
-- Shapeless recipes
|
2017-07-28 17:23:13 +02:00
|
|
|
elseif pattern.type == "shapeless" then
|
2017-07-28 17:41:04 +02:00
|
|
|
for colorid, colortab in pairs(mcl_banners.colors) do
|
|
|
|
local banner = "mcl_banners:banner_item_"..colortab[1]
|
|
|
|
local orig = pattern[1]
|
|
|
|
local recipe = {}
|
|
|
|
for r=1, #orig do
|
|
|
|
if orig[r] == e then
|
|
|
|
recipe[r] = banner
|
|
|
|
else
|
|
|
|
recipe[r] = orig[r]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
type = "shapeless",
|
|
|
|
output = banner,
|
|
|
|
recipe = recipe,
|
|
|
|
})
|
|
|
|
end
|
2017-07-28 17:23:13 +02:00
|
|
|
end
|
|
|
|
end
|
2017-07-28 14:54:34 +02:00
|
|
|
|