本篇教程的视频
本篇教程的源代码
查看源文件
配方的话,原版中有很多类型,不过,值得注意的是,这些配方其实都是各类方块实体的配方
像工作台,有有序合成和无序合成这两种合成配方;熔炉、高炉有自己的熔炼配方;
营火、烟熏炉有食物加工的配方;切石机也有自己的配方等等
后面我们讲到方块实体的时候,也会来写我们自己方块实体的配方
和前面的战利品列表一样,我们直接来看原版的那些配方文件
那些配方文件也是放在data下的,recipe文件夹中就放了原版所有的配方文件
有序合成
我们先来看看常用的,工作台相关的有序合成配方
这个是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
| { "type": "minecraft:crafting_shaped", "category": "equipment", "key": { "#": { "item": "minecraft:stick" }, "X": { "item": "minecraft:flint" }, "Y": { "item": "minecraft:feather" } }, "pattern": [ "X", "#", "Y" ], "result": { "count": 4, "id": "minecraft:arrow" } }
|
type是minecraft:crafting_shaped,即有序合成
category是配方分类,在工作台中,游戏会根据这个将合成物分到相应的标签页,
这里是equipment,即装备,还有misc杂项、building建筑方块等等
下面的key和pattern可以一起来看,pattern是合成模式,有序合成需要遵循这个模式才能进行合成,
这个模式中填的就是一些字符,而这些字符对应的就是key中的物品
值得注意的是,pattern中,每一行的字符数量必须相同,否则游戏无法正确读取,
我们可以拿另一个配方来看看
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| { "type": "minecraft:crafting_shaped", "category": "misc", "key": { "#": { "tag": "minecraft:planks" } }, "pattern": [ "# #", " # " ], "result": { "count": 4, "id": "minecraft:bowl" } }
|
这个是bowl碗的配方,可以看到,pattern中只有两行,但是每一行的字符数量都是3,
缺失的部分是用空格代替的
不过,你或许注意到了,这个key中,填的是tag而不是item
tag是可以用在配方中的,不过,具体内容我们会在Tag的教程中讲解
result是合成结果,count是数量,id是合成物(在1.21之前的版本中,还是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, "id": "minecraft:diamond" } }
|
type是minecraft: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 37
| { "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": { "count": 1, "id": "minecraft:bamboo_block" } }
|
这是竹子方块的配方,竹子合成竹块,可以看到,ingredients里面填了9个竹子
(不过我好奇的是,为什么它不用有序合成)
熔炼配方
熔炉
我们接下来看熔炉的配方
这里是粗铜熔炼为铜锭的配方
1 2 3 4 5 6 7 8 9 10 11 12 13
| { "type": "minecraft:smelting", "category": "misc", "cookingtime": 200, "experience": 0.7, "group": "copper_ingot", "ingredient": { "item": "minecraft:raw_copper" }, "result": { "id": "minecraft:copper_ingot" } }
|
type是minecraft:smelting,即熔炉配方
category是配方分类,和前面一样
cookingtime是烹饪时间,单位是tick,1秒=20tick,所以200tick就是10秒
experience是掉落经验,也就是熔炼后掉落铜锭时,玩家会得到的经验
group是配方的组,可以缺省,写的话也可以直接写最终产物
ingredient是熔炼材料,result是熔炼产物
熔炉的话,是可以加工一部分食物的,比如将一些生肉加工为熟肉,但是在高炉中,食物是不能加工的
高炉
接下来我们看看高炉的配方,同样还是粗铜熔炼为铜锭的
1 2 3 4 5 6 7 8 9 10 11 12 13
| { "type": "minecraft:blasting", "category": "misc", "cookingtime": 100, "experience": 0.7, "group": "copper_ingot", "ingredient": { "item": "minecraft:copper_ore" }, "result": { "id": "minecraft:copper_ingot" } }
|
type是minecraft:blasting,即高炉配方
剩下的只有cookingtime是比熔炉短了一半,即5秒就能熔炼好
当然,高炉虽然加工更快,燃料消耗也更快,不过每单位的燃料加工的材料数是一样的,
即一个煤可以加工8个粗矿,这在熔炉和高炉中都是一样的
食物相关
营火
接下来我们看看食物相关的配方,首先是营火
这个是生牛肉加工为熟牛肉
1 2 3 4 5 6 7 8 9 10 11 12
| { "type": "minecraft:campfire_cooking", "category": "food", "cookingtime": 600, "experience": 0.35, "ingredient": { "item": "minecraft:beef" }, "result": { "id": "minecraft:cooked_beef" } }
|
形式上和熔炉、高炉的差不多
type是minecraft:campfire_cooking,即营火配方
cookingtime则远远高于在熔炉中的时间,这里要30秒,是熔炉的3倍
烟熏炉
接下来我们看看烟熏炉的配方,同样是生牛肉加工为熟牛肉
1 2 3 4 5 6 7 8 9 10 11 12
| { "type": "minecraft:smoking", "category": "food", "cookingtime": 100, "experience": 0.35, "ingredient": { "item": "minecraft:beef" }, "result": { "id": "minecraft:cooked_beef" } }
|
type是minecraft:smoking,即烟熏炉配方
cookingtime则短得多,只有5秒,是熔炉的一半
编写配方
好了,以上我们就先列举这么一些,另外的不同种类的配方同学们可以自行研究
不过,其实与配方相关联的还有进度,当然和配方相关的进度是隐式的,
并不会像我们按L进入进度界面显示的那些
配方相关的进度,在游戏中的话,就像我们获得了原木,那么就会解锁木板相关的配方;
当我们溜达到水里,就会解锁船的配方等等,这就是配方相关联的进度
接下来我们就来自己写我们模组的配方
同样,我们在data/tutorial_mod下新建recipe文件夹,注意单数
有序合成
这里我们写一个ice_ether_block.json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| { "type": "minecraft:crafting_shaped", "category": "building", "key": { "#": { "item": "tutorial_mod:ice_ether" } }, "pattern": [ "###", "###", "###" ], "result": { "count": 1, "id": "tutorial_mod:ice_ether_block" } }
|
注意合成物和最终产物的命名空间和名字,不要写错了,不然游戏也无法正确读取
无序合成
这里我们写一个ice_ether.json
1 2 3 4 5 6 7 8 9 10 11 12 13
| { "type": "minecraft:crafting_shapeless", "category": "misc", "ingredients": [ { "item": "tutorial_mod:ice_ether_block" } ], "result": { "count": 9, "id": "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 12 13
| { "type": "minecraft:smelting", "category": "misc", "cookingtime": 200, "experience": 0.7, "group": "ice_ether", "ingredient": { "item": "tutorial_mod:raw_ice_ether" }, "result": { "id": "tutorial_mod:ice_ether" } }
|
高炉
这里我们写一个ie_from_blasting_rie.json
1 2 3 4 5 6 7 8 9 10 11 12 13
| { "type": "minecraft:blasting", "category": "misc", "cookingtime": 100, "experience": 0.7, "group": "ice_ether", "ingredient": { "item": "tutorial_mod:raw_ice_ether" }, "result": { "id": "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", "ingredients": [ { "item": "tutorial_mod:ice_ether" }, { "item": "minecraft:stone" } ], "result": { "count": 1, "id": "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
| { "type": "minecraft:crafting_shaped", "category": "misc", "key": { "#": { "item": "minecraft:beetroot" } }, "pattern": [ "###" ], "result": { "count": 3, "id": "minecraft:sugar" } }
|
再如甜菜合成糖,这样甜菜就成为糖料作物了
测试
那么现在,我们就可以进入游戏去测试一下
由于我们没有写进度文件,所有只有我们自己手动合成上面写的那些东西时,
才会在右上角弹出配方的解锁提示