commit | author | age
|
aa8af0
|
1 |
|
N |
2 |
technic.recipes = {} |
|
3 |
function technic.register_recipe_type(typename, desc) |
|
4 |
if unified_inventory and unified_inventory.register_craft_type then |
|
5 |
unified_inventory.register_craft_type(typename, { |
|
6 |
description = desc, |
|
7 |
height = 1, |
|
8 |
width = 1, |
|
9 |
}) |
|
10 |
end |
|
11 |
technic.recipes[typename] = {} |
|
12 |
end |
|
13 |
|
|
14 |
function technic.register_recipe(typename, data) |
|
15 |
local src = ItemStack(data.input):get_name() |
|
16 |
technic.recipes[typename][src] = data |
|
17 |
if unified_inventory then |
|
18 |
unified_inventory.register_craft({ |
|
19 |
type = typename, |
|
20 |
output = data.output, |
|
21 |
items = {data.input}, |
|
22 |
width = 0, |
|
23 |
}) |
|
24 |
end |
|
25 |
end |
|
26 |
|
|
27 |
function technic.get_recipe(typename, item) |
|
28 |
if typename == "cooking" then -- Already builtin in Minetest, so use that |
|
29 |
local result = minetest.get_craft_result({ |
|
30 |
method = "cooking", |
|
31 |
width = 1, |
|
32 |
items = {item}}) |
|
33 |
-- Compatibility layer |
|
34 |
if not result or result.time == 0 then |
|
35 |
return nil |
|
36 |
else |
|
37 |
return {time = result.time, |
|
38 |
input = item:get_name(), |
|
39 |
output = result.item:to_string()} |
|
40 |
end |
|
41 |
end |
|
42 |
local recipe = technic.recipes[typename][item:get_name()] |
|
43 |
if recipe and item:get_count() >= ItemStack(recipe.input):get_count() then |
|
44 |
return recipe |
|
45 |
else |
|
46 |
return nil |
|
47 |
end |
|
48 |
end |
|
49 |
|
|
50 |
-- Handle aliases |
|
51 |
minetest.after(0.01, function () |
|
52 |
for _, recipes_list in pairs(technic.recipes) do |
|
53 |
for ingredient, recipe in pairs(recipes_list) do |
|
54 |
ingredient = minetest.registered_aliases[ingredient] |
|
55 |
while ingredient do |
|
56 |
recipes_list[ingredient] = recipe |
|
57 |
ingredient = minetest.registered_aliases[ingredient] |
|
58 |
end |
|
59 |
end |
|
60 |
end |
|
61 |
end) |
|
62 |
|
|
63 |
|