Shift to table lookup for brewing combinations. Fix issue with brewing only if all slots filled.

bzoss 2020-05-27 21:15:46 -04:00
parent 861aedbfa3
commit bcdb37800d
2 changed files with 30 additions and 27 deletions

@ -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

@ -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