Skip to content

Commit bc9a775

Browse files
authored
Add support for craftguide mod recipe registration (#174)
Co-authored-by: sfence <sfence.software@gmail.com> minetest-mods/technic#584
1 parent ce79586 commit bc9a775

File tree

4 files changed

+55
-34
lines changed

4 files changed

+55
-34
lines changed

.luacheckrc

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,32 @@ exclude_files = {
66
}
77

88
globals = {
9-
"technic", "technic_cnc", "minetest", "wrench"
9+
"technic", "technic_cnc", "minetest", "wrench"
1010
}
1111

1212
read_globals = {
1313
-- Lua
14-
string = {fields = {"split", "trim"}},
15-
table = {fields = {"copy", "getn"}},
16-
14+
string = {fields = {"split", "trim"}},
15+
table = {fields = {"copy", "getn"}},
16+
1717
-- Minetest
18-
"PseudoRandom", "ItemStack",
18+
"PseudoRandom", "ItemStack",
1919
"VoxelArea", "VoxelManip",
2020
"Settings", "vector",
21-
21+
2222
-- Mods
23-
"default", "stairsplus",
23+
"default", "stairsplus",
2424
"screwdriver", "bucket",
2525
"digilines", "pipeworks",
2626
"mesecon", "moretrees",
27-
"unified_inventory", "protector",
28-
"unifieddyes", "digiline_remote",
29-
"monitoring", "drawers", "mg",
30-
27+
"unified_inventory", "protector",
28+
"unifieddyes", "digiline_remote",
29+
"monitoring", "drawers", "mg",
30+
"craftguide", "i3",
31+
3132
-- Only used in technic/machines/MV/lighting.lua (disabled)
3233
"isprotect", "homedecor_expect_infinite_stacks",
33-
34+
3435
-- TODO: Remove after translation update
3536
"intllib"
3637
}

technic/depends.txt

Lines changed: 0 additions & 15 deletions
This file was deleted.

technic/machines/register/recipes.lua

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
11
local have_ui = minetest.get_modpath("unified_inventory")
2+
local have_cg = minetest.get_modpath("craftguide")
3+
local have_i3 = minetest.get_modpath("i3")
24

35
technic.recipes = { cooking = { input_size = 1, output_size = 1 } }
46
function technic.register_recipe_type(typename, origdata)
57
local data = {}
68
for k, v in pairs(origdata) do data[k] = v end
79
data.input_size = data.input_size or 1
810
data.output_size = data.output_size or 1
9-
if have_ui and unified_inventory.register_craft_type and data.output_size == 1 then
10-
unified_inventory.register_craft_type(typename, {
11-
description = data.description,
12-
width = data.input_size,
13-
height = 1,
14-
})
11+
if data.output_size == 1 then
12+
if have_ui and unified_inventory.register_craft_type then
13+
unified_inventory.register_craft_type(typename, {
14+
description = data.description,
15+
width = data.input_size,
16+
height = 1,
17+
})
18+
end
19+
if have_cg and craftguide.register_craft_type then
20+
craftguide.register_craft_type(typename, {
21+
description = data.description,
22+
})
23+
end
24+
if have_i3 then
25+
i3.register_craft_type(typename, {
26+
description = data.description,
27+
})
28+
end
1529
end
1630
data.recipes = {}
1731
technic.recipes[typename] = data
@@ -59,6 +73,27 @@ local function register_recipe(typename, data)
5973
width = 0,
6074
})
6175
end
76+
if (have_cg or have_i3) and technic.recipes[typename].output_size == 1 then
77+
local result = data.output
78+
if (type(result)=="table") then
79+
result = result[1]
80+
end
81+
local items = table.concat(data.input, ", ")
82+
if have_cg and craftguide.register_craft then
83+
craftguide.register_craft({
84+
type = typename,
85+
result = result,
86+
items = {items},
87+
})
88+
end
89+
if have_i3 then
90+
i3.register_craft({
91+
type = typename,
92+
result = result,
93+
items = {items},
94+
})
95+
end
96+
end
6297
end
6398

6499
function technic.register_recipe(typename, data)

technic/mod.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
name = technic
22
depends = default, pipeworks, technic_worldgen, basic_materials
3-
optional_depends = bucket, screwdriver, mesecons, mesecons_mvps, digilines, digiline_remote, intllib, unified_inventory, vector_extras, dye, monitoring
3+
optional_depends = bucket, screwdriver, mesecons, mesecons_mvps, digilines, digiline_remote, intllib, unified_inventory, vector_extras, dye, monitoring, craftguide,i3

0 commit comments

Comments
 (0)