From bcdb37800db5914fa0b97b451c8100d0e2a07bfd Mon Sep 17 00:00:00 2001 From: bzoss Date: Wed, 27 May 2020 21:15:46 -0400 Subject: [PATCH] Shift to table lookup for brewing combinations. Fix issue with brewing only if all slots filled. --- mods/ITEMS/mcl_brewing/init.lua | 16 +++++-------- mods/ITEMS/mcl_potions/init.lua | 41 +++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/mods/ITEMS/mcl_brewing/init.lua b/mods/ITEMS/mcl_brewing/init.lua index 3b8577a31c..b87ae04a10 100755 --- a/mods/ITEMS/mcl_brewing/init.lua +++ b/mods/ITEMS/mcl_brewing/init.lua @@ -73,9 +73,9 @@ end local function brewable(inv) local ingredient = inv:get_stack("input",1):get_name() - local stands = {"","",""} + local stands = {} local stand_size = inv:get_size("stand") - local was_alchemy = true + local was_alchemy = {false,false,false} for i=1,stand_size do @@ -84,14 +84,16 @@ local function brewable(inv) local alchemy = mcl_potions.get_alchemy(ingredient, bottle) if alchemy then stands[i] = alchemy + was_alchemy[i] = true else stands[i] = bottle - was_alchemy = false end end -- if any stand holds a new potion, return the list of new potions - if was_alchemy then return stands end + for i=1,table.getn(was_alchemy) do + if was_alchemy[i] then return stands end + end return false end @@ -205,12 +207,6 @@ local function brewing_stand_timer(pos, elapsed) fuel_totaltime = fuel.time end - -- for i=1, inv:get_size("stand") do - -- if stand_list[i]:is_empty() then - -- stand_timer = 0 - -- end - -- end - --update formspec local formspec = brewing_formspec diff --git a/mods/ITEMS/mcl_potions/init.lua b/mods/ITEMS/mcl_potions/init.lua index ac2d1c26c0..fe2e84a2d6 100644 --- a/mods/ITEMS/mcl_potions/init.lua +++ b/mods/ITEMS/mcl_potions/init.lua @@ -359,26 +359,33 @@ minetest.register_craftitem("mcl_potions:swiftness", { mcl_potions = {} +function key_in_table(table,key) + return table[key] ~= nil +end + +local water_table = { + ["mcl_nether:nether_wart_item"] = "mcl_potions:potion_awkward", + ["mcl_potions:fermented_spider_eye"] = "mcl_potions:weakness", +} +local awkward_table = { + ["mcl_potions:speckled_melon"] = "mcl_potions:healing", + ["mcl_farming:carrot_item_gold"] = "mcl_potions:night_vision", + ["mcl_core:sugar"] = "mcl_potions:swiftness", +} +local output_table = { + ["mcl_potions:potion_river_water"] = water_table, + ["mcl_potions:potion_water"] = water_table, + ["mcl_potions:potion_awkward"] = awkward_table, +} + -- Compare two ingredients for compatable alchemy function mcl_potions.get_alchemy(ingr, pot) - if pot == "mcl_potions:potion_river_water" or pot == "mcl_potions:potion_water" then - if ingr == "mcl_nether:nether_wart_item" then - return "mcl_potions:potion_awkward" - elseif ingr == "mcl_potions:fermented_spider_eye" then - return "mcl_potions:weakness" + if output_table[pot] ~= nil then + local brew_table = output_table[pot] + if brew_table[ingr] ~= nil then + return brew_table[ingr] end - - elseif pot == "mcl_potions:potion_awkward" then - if ingr == "mcl_potions:speckled_melon" then - return "mcl_potions:healing" - elseif ingr == "mcl_farming:carrot_item_gold" then - return "mcl_potions:night_vision" - elseif ingr == "mcl_core:sugar" then - return "mcl_potions:swiftness" - end - - else - return false end + return false end