generated from your-land/yl_template
Implements feature recipes
This commit is contained in:
parent
9b71ca5085
commit
28d53ff0f2
@ -81,4 +81,5 @@ See [LICENSE.md](https://gitea.your-land.de/your-land/yl_canned_food_mtg/src/LIC
|
||||
|
||||
## Thank you
|
||||
|
||||
* Styxcolor
|
||||
* Styxcolor
|
||||
* tour
|
||||
@ -1 +1,73 @@
|
||||
-- recipes
|
||||
-- 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
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local itemcache = {}
|
||||
|
||||
local vessel = "vessels:glass_bottle"
|
||||
|
||||
itemcache[vessel] = true
|
||||
|
||||
for _, recipe in ipairs(yl_canned_food_mtg.recipes) do
|
||||
itemcache[recipe.out] = true
|
||||
|
||||
local ingredient = recipe.base_mod .. ":" .. recipe.base_item
|
||||
itemcache[ingredient] = true
|
||||
|
||||
for _, additive in ipairs(recipe.additives) do
|
||||
itemcache[additive] = true
|
||||
end
|
||||
end
|
||||
|
||||
local item_good = {}
|
||||
|
||||
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
|
||||
|
||||
for _, recipe in ipairs(yl_canned_food_mtg.recipes) do
|
||||
|
||||
local crafting = {}
|
||||
-- vessel
|
||||
table.insert(crafting, vessel)
|
||||
-- additive
|
||||
for _, additive in ipairs(recipe.additives) do
|
||||
table.insert(crafting, additive)
|
||||
end
|
||||
-- ingredient
|
||||
local ingredient = recipe.base_mod .. ":" .. recipe.base_item
|
||||
|
||||
for i = recipe.base_amount, 1, -1 do
|
||||
table.insert(crafting, ingredient)
|
||||
end
|
||||
|
||||
if (item_good[vessel] ~= false) and (item_good[additive] ~= false) and (item_good[ingredient] ~= false) then
|
||||
-- register the craft
|
||||
minetest.register_craft({
|
||||
output = recipe.out,
|
||||
type = "shapeless",
|
||||
recipe = crafting
|
||||
})
|
||||
|
||||
amount = amount + 1
|
||||
end
|
||||
end
|
||||
|
||||
yl_canned_food_mtg.log("recipes integration: " .. dump(amount))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user