From 221a7ff8921e45071db712dbe8afa67f60a4b0f5 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 29 Jul 2017 00:12:21 +0200 Subject: [PATCH] Implement shapeless banner crafting --- mods/ITEMS/mcl_banners/patterncraft.lua | 28 +++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_banners/patterncraft.lua b/mods/ITEMS/mcl_banners/patterncraft.lua index 54aa4c1bf..90149fb9f 100644 --- a/mods/ITEMS/mcl_banners/patterncraft.lua +++ b/mods/ITEMS/mcl_banners/patterncraft.lua @@ -19,7 +19,7 @@ local patterns = { { e, "mcl_core:brick_block", d }, }, ["circle"] = { - name = "%s Circle", + name = "%s Roundel", { e, e, e }, { e, d, e }, { e, e, e }, @@ -344,7 +344,31 @@ local banner_pattern_craft = function(itemstack, player, old_craft_grid, craft_i end elseif pattern.type == "shapeless" then - -- TODO + local orig = pattern[1] + local no_mismatches_so_far = true + -- This code compares the craft grid with the required items + for o=1, #orig do + local item_ok = false + for i=1, max_i do + local itemname = old_craft_grid[i]:get_name() + if (orig[o] == e) or -- Empty slot: Always wins + (orig[o] ~= e and orig[o] == itemname) or -- non-empty slot: Exact item match required + (orig[o] == d and minetest.get_item_group(itemname, "dye") == 1) then -- Dye slot + item_ok = true + break + end + end + -- Sorry, item not found. :-( + if not item_ok then + no_mismatches_so_far = false + break + end + end + -- Ladies and Gentlemen, we have a winner! + if no_mismatches_so_far then + matching_pattern = pattern_name + break + end end if matching_pattern then