From d27ea86306e3170fd03695ec2b3259d2a2f148da Mon Sep 17 00:00:00 2001 From: AliasAlreadyTaken Date: Sun, 14 Jul 2024 04:09:52 +0200 Subject: [PATCH] Fixes additives nil and formatting --- feature_eat.lua | 9 +++------ feature_recipes.lua | 37 ++++++++++++++++++++++++----------- feature_unified_inventory.lua | 12 +++++++----- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/feature_eat.lua b/feature_eat.lua index 5b409cd..5a03764 100644 --- a/feature_eat.lua +++ b/feature_eat.lua @@ -1,11 +1,8 @@ -- item eat integration - -if (yl_canned_food_mtg.settings.enable_eat ~= true) then - return false -end +if (yl_canned_food_mtg.settings.enable_eat ~= true) then return false end -- dependencies -if (minetest.get_modpath("vessels") == nil) then +if (minetest.get_modpath("vessels") == nil) then yl_canned_food_mtg.log("feature item_eat enabled, but mod vessels not found") return false end @@ -22,7 +19,7 @@ for _, recipe in ipairs(yl_canned_food_mtg.recipes) do -- pickled local redefinition_plus = { - on_use = minetest.item_eat(recipe.nutrition*2, "vessels:glass_bottle") + on_use = minetest.item_eat(recipe.nutrition * 2, "vessels:glass_bottle") } minetest.override_item(recipe.out .. "_plus", redefinition_plus) diff --git a/feature_recipes.lua b/feature_recipes.lua index 420db62..6f2aa52 100644 --- a/feature_recipes.lua +++ b/feature_recipes.lua @@ -1,14 +1,11 @@ -- recipes integration - if (yl_canned_food_mtg.settings.enable_recipes ~= true) then return false end local amount = 0 local function group_has_member(group) for itemname, _ in pairs(minetest.registered_items) do - if minetest.get_item_group(itemname, group) ~= 0 then - return true - end + if minetest.get_item_group(itemname, group) ~= 0 then return true end end return false end @@ -25,19 +22,16 @@ for _, recipe in ipairs(yl_canned_food_mtg.recipes) do local ingredient = recipe.base_mod .. ":" .. recipe.base_item itemcache[ingredient] = true - for _, additive in ipairs(recipe.additives) do - itemcache[additive] = true - end + for _, additive in ipairs(recipe.additives) do itemcache[additive] = true end end local item_good = {} -for item,_ in pairs(itemcache) do +for item, _ in pairs(itemcache) do local groupname = item:match("^group:(.*)") if (groupname == nil) then item_good[item] = (minetest.registered_items[item] ~= nil) else - core.log("action","groupname="..dump(groupname)) item_good[item] = group_has_member(groupname) end end @@ -45,20 +39,38 @@ end for _, recipe in ipairs(yl_canned_food_mtg.recipes) do local crafting = {} + local success = true + -- vessel table.insert(crafting, vessel) + if (item_good[vessel] ~= false) then + success = success and true + else + success = false + end + -- additive for _, additive in ipairs(recipe.additives) do table.insert(crafting, additive) + if (item_good[additive] ~= false) then + success = success and true + else + success = false + end end -- ingredient local ingredient = recipe.base_mod .. ":" .. recipe.base_item for i = recipe.base_amount, 1, -1 do table.insert(crafting, ingredient) + if (item_good[ingredient] ~= false) then + success = success and true + else + success = false + end end - - if (item_good[vessel] ~= false) and (item_good[additive] ~= false) and (item_good[ingredient] ~= false) then + + if (success == true) then -- register the craft minetest.register_craft({ output = recipe.out, @@ -67,6 +79,9 @@ for _, recipe in ipairs(yl_canned_food_mtg.recipes) do }) amount = amount + 1 + else + minetest.log("warning", + yl_canned_food_mtg.t("recipe_not_good", recipe.out)) end end diff --git a/feature_unified_inventory.lua b/feature_unified_inventory.lua index 24b37c9..168cbb2 100644 --- a/feature_unified_inventory.lua +++ b/feature_unified_inventory.lua @@ -1,17 +1,19 @@ -- unified_inventory integration - if (yl_canned_food_mtg.settings.enable_unified_inventory ~= true) then return false end -- dependencies -if (minetest.get_modpath("unified_inventory") == nil) then - yl_canned_food_mtg.log("feature unfied_inventory enabled, but mod unfied_inventory not found") +if (minetest.get_modpath("unified_inventory") == nil) then + yl_canned_food_mtg.log( + "feature unfied_inventory enabled, but mod unfied_inventory not found") return false end -assert((type(unified_inventory.register_craft_type) == "function"), "register_craft_type does not exist in unified_inventory") -assert((type(unified_inventory.register_craft) == "function"), "register_craft does not exist in unified_inventory") +assert((type(unified_inventory.register_craft_type) == "function"), + "register_craft_type does not exist in unified_inventory") +assert((type(unified_inventory.register_craft) == "function"), + "register_craft does not exist in unified_inventory") unified_inventory.register_craft_type("yl_canned_food", { description = yl_canned_food_mtg.t(