Skip to content

Commit

Permalink
add registered craft recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
HybridDog committed Aug 24, 2014
1 parent ce5706c commit b0ab5c8
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions craft_guide/init.lua
Expand Up @@ -13,6 +13,63 @@ MAIN LOADER
-- load api
dofile(minetest.get_modpath("craft_guide").."/api_craft_guide.lua")

-- register existing recipes
local function tab_to_recipe(x, t)
local tab
if x == 1 then
return {
{t[1]},
{t[2]},
{t[3]}
}
end
if x == 2 then
return {
{t[1], t[2]},
{t[3], t[4]},
{t[5], t[6]}
}
end
if x == 3 then
return {
{t[1], t[2], t[3]},
{t[4], t[5], t[6]},
{t[7], t[8], t[9]}
}
end
end

for name,def in pairs(minetest.registered_items) do
if (not def.groups.not_in_creative_inventory
or def.groups.not_in_creative_inventory == 0)
and def.description
and def.description ~= "" then
local recipes = minetest.get_all_craft_recipes(name)
if recipes then
for _, recipe in ipairs(recipes) do
local tab = {}
tab.type = recipe.type
if tab.type == "normal" then
tab.type = nil
end
tab.output = name

if not tab.type then
local x = recipe.width
if x == 0 then
x = 3
end
tab.recipe = tab_to_recipe(x, recipe.items)
else
tab.recipe = recipe.items[1]
end

craft_guide.register_craft(tab)
end
end
end
end

-- override minetest.register_craft
local minetest_register_craft = minetest.register_craft
minetest.register_craft = function (options)
Expand Down

0 comments on commit b0ab5c8

Please sign in to comment.