本篇教程的视频

本篇教程的源代码

GitHub地址:TutorialMod-Recipe-1.20.1

本篇教程目标

  • 理解配方文件基本格式
  • 学会为模组方块、物品添加配方

查看源文件

配方的话,原版中有很多类型,不过,值得注意的是,这些配方其实都是各类方块实体的配方

工作台,有有序合成无序合成这两种合成配方;熔炉高炉有自己的熔炼配方;
营火烟熏炉有食物加工的配方;切石机也有自己的配方等等

后面我们讲到方块实体的时候,也会来写我们自己方块实体的配方

和前面的战利品列表一样,我们直接来看原版的那些配方文件

那些配方文件也是放在data下的,recipes文件夹中就放了原版所有的配方文件

有序合成

我们先来看看常用的,工作台相关的有序合成配方

这个是arrow箭的配方

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
"type": "minecraft:crafting_shaped",
"category": "equipment",
"key": {
"#": {
"item": "minecraft:stick"
},
"X": {
"item": "minecraft:flint"
},
"Y": {
"item": "minecraft:feather"
}
},
"pattern": [
"X",
"#",
"Y"
],
"result": {
"count": 4,
"item": "minecraft:arrow"
},
"show_notification": true
}

typeminecraft:crafting_shaped,即有序合成

category是配方分类,在工作台中,游戏会根据这个将合成物分到相应的标签页,
这里是equipment,即装备,还有misc杂项、building建筑方块等等

下面的keypattern可以一起来看,pattern是合成模式,有序合成需要遵循这个模式才能进行合成,
这个模式中填的就是一些字符,而这些字符对应的就是key中的物品

值得注意的是,pattern中,每一行的字符数量必须相同,否则游戏无法正确读取,
我们可以拿另一个配方来看看

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"key": {
"#": {
"tag": "minecraft:planks"
}
},
"pattern": [
"# #",
" # "
],
"result": {
"count": 4,
"item": "minecraft:bowl"
},
"show_notification": true
}

这个是bowl碗的配方,可以看到,pattern中只有两行,但是每一行的字符数量都是3
缺失的部分是用空格代替的

不过,你或许注意到了,这个key中,填的是tag而不是item

tag是可以用在配方中的,不过,具体内容我们会在Tag的教程中讲解

result是合成结果,count是数量,item是合成物

show_notification是是否弹出解锁配方的提示,也就是游戏右上角蹦出的那些信息

无序合成

接下来我们看看无序合成的配方,无序合成就没有有序合成的合成模式了

这是diamond钻石的配方,钻石块合成9钻石

1
2
3
4
5
6
7
8
9
10
11
12
13
{
"type": "minecraft:crafting_shapeless",
"category": "misc",
"ingredients": [
{
"item": "minecraft:diamond_block"
}
],
"result": {
"count": 9,
"item": "minecraft:diamond"
}
}

typeminecraft:crafting_shapeless,即无序合成

ingredients是合成材料,这里只有一个,就是钻石块

要注意的是,虽然result里面可以填数量,但是ingredients里面是不能填数量的,
有几个就只能写几个,且最多不能超过9个

比如我们看看另外一个

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{
"type": "minecraft:crafting_shapeless",
"category": "building",
"ingredients": [
{
"item": "minecraft:bamboo"
},
{
"item": "minecraft:bamboo"
},
{
"item": "minecraft:bamboo"
},
{
"item": "minecraft:bamboo"
},
{
"item": "minecraft:bamboo"
},
{
"item": "minecraft:bamboo"
},
{
"item": "minecraft:bamboo"
},
{
"item": "minecraft:bamboo"
},
{
"item": "minecraft:bamboo"
}
],
"result": {
"item": "minecraft:bamboo_block"
}
}

这是竹子的配方,竹子合成竹块,可以看到,ingredients里面填了9个竹子
(不过我好奇的是,为什么它不用有序合成)

熔炼配方

熔炉

我们接下来看熔炉的配方

这里是粗铜熔炼为铜锭的配方

1
2
3
4
5
6
7
8
9
10
11
{
"type": "minecraft:smelting",
"category": "misc",
"cookingtime": 200,
"experience": 0.7,
"group": "copper_ingot",
"ingredient": {
"item": "minecraft:raw_copper"
},
"result": "minecraft:copper_ingot"
}

typeminecraft:smelting,即熔炉配方

category是配方分类,和前面一样

cookingtime是烹饪时间,单位是tick1秒=20tick,所以200tick就是10秒

experience掉落经验,也就是熔炼后掉落铜锭时,玩家会得到的经验

group是配方的组,可以缺省,写的话也可以直接写最终产物

ingredient是熔炼材料,result是熔炼产物

熔炉的话,是可以加工一部分食物的,比如将一些生肉加工为熟肉,但是在高炉中,食物是不能加工的

高炉

接下来我们看看高炉的配方,同样还是粗铜熔炼为铜锭的

1
2
3
4
5
6
7
8
9
10
11
{
"type": "minecraft:blasting",
"category": "misc",
"cookingtime": 100,
"experience": 0.7,
"group": "copper_ingot",
"ingredient": {
"item": "minecraft:raw_copper"
},
"result": "minecraft:copper_ingot"
}

typeminecraft:blasting,即高炉配方

剩下的只有cookingtime是比熔炉短了一半,即5秒就能熔炼好

当然,高炉虽然加工更快,燃料消耗也更快,不过每单位的燃料加工的材料数是一样的,
即一个煤可以加工8个粗矿,这在熔炉和高炉中都是一样的

食物相关

营火

接下来我们看看食物相关的配方,首先是营火

这个是生牛肉加工为熟牛肉

1
2
3
4
5
6
7
8
9
10
{
"type": "minecraft:campfire_cooking",
"category": "food",
"cookingtime": 600,
"experience": 0.35,
"ingredient": {
"item": "minecraft:beef"
},
"result": "minecraft:cooked_beef"
}

形式上和熔炉、高炉的差不多

typeminecraft:campfire_cooking,即营火配方

cookingtime则远远高于在熔炉中的时间,这里要30秒,是熔炉的3倍

烟熏炉

接下来我们看看烟熏炉的配方,同样是生牛肉加工为熟牛肉

1
2
3
4
5
6
7
8
9
10
{
"type": "minecraft:smoking",
"category": "food",
"cookingtime": 100,
"experience": 0.35,
"ingredient": {
"item": "minecraft:beef"
},
"result": "minecraft:cooked_beef"
}

typeminecraft:smoking,即烟熏炉配方

cookingtime则短得多,只有5秒,是熔炉的一半

编写配方

好了,以上我们就先列举这么一些,另外的不同种类的配方同学们可以自行研究

不过,其实与配方相关联的还有进度,当然和配方相关的进度是隐式的,并不会像我们按L进入进度界面显示的那些

配方相关的进度,在游戏中的话,就像我们获得了原木,那么就会解锁木板相关的配方;
当我们溜达到水里,就会解锁的配方等等,这就是配方相关联的进度

不过这个东西,我们这里就先不讲了,下一期讲数据生成的时候,我们还是会写这个东西的

接下来我们就来自己写我们模组的配方

同样,我们在我们自己的命名空间下新建recipes文件夹

有序合成

这里我们写一个ice_ether_block.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"group": "ice_ether_block",
"key": {
"#": {
"item": "tutorial-mod:ice_ether"
}
},
"pattern": [
"###",
"###",
"###"
],
"result": {
"item": "tutorial-mod:ice_ether_block"
},
"show_notification": true
}

注意合成物和最终产物的命名空间名字,不要写错了,不然游戏也无法正确读取

无序合成

这里我们写一个ice_ether.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
"type": "minecraft:crafting_shapeless",
"category": "building",
"group": "ice_ether",
"ingredients": [
{
"item": "tutorial-mod:ice_ether_block"
}
],
"result": {
"count": 9,
"item": "tutorial-mod:ice_ether"
}
}

熔炼配方

熔炉

这里我们写一个ie_from_smelting_rie.json

即raw ice ether熔炼为ice ether

1
2
3
4
5
6
7
8
9
10
11
{
"type": "minecraft:smelting",
"category": "misc",
"cookingtime": 200,
"experience": 0.7,
"group": "ice_ether",
"ingredient": {
"item": "tutorial-mod:raw_ice_ether"
},
"result": "tutorial-mod:ice_ether"
}

高炉

这里我们写一个ie_from_blasting_rie.json

1
2
3
4
5
6
7
8
9
10
11
{
"type": "minecraft:blasting",
"category": "misc",
"cookingtime": 100,
"experience": 0.7,
"group": "ice_ether",
"ingredient": {
"item": "tutorial-mod:raw_ice_ether"
},
"result": "tutorial-mod:ice_ether"
}

举一反三

我们再来举一反三一下,多写几个

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
"type": "minecraft:crafting_shapeless",
"category": "building",
"group": "ice_ether_ore",
"ingredients": [
{
"item": "tutorial-mod:raw_ice_ether"
},
{
"item": "minecraft:stone"
}
],
"result": {
"item": "tutorial-mod:ice_ether_ore"
}
}

这是用原版的stone和我们的raw ice ether合成ice ether ore的配方

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"group": "sugar",
"key": {
"#": {
"item": "minecraft:beetroot"
}
},
"pattern": [
"###"
],
"result": {
"item": "minecraft:sugar",
"count": 3
},
"show_notification": true
}

再如甜菜合成,这样甜菜就成为糖料作物了

测试

那么现在,我们就可以进入游戏去测试一下

由于我们没有写进度文件,所有只有我们自己手动合成上面写的那些东西时,
才会在右上角弹出配方的解锁提示