本篇教程的视频
本篇教程的源代码
本篇教程目标
- 理解
配方
文件基本格式
- 学会为模组方块、物品添加
配方
查看源文件
配方的话,原版中有很多类型,不过,值得注意的是,这些配方其实都是各类方块实体
的配方
像工作台
,有有序合成
和无序合成
这两种合成配方;熔炉
、高炉
有自己的熔炼
配方;
营火
、烟熏炉
有食物加工的配方;切石机
也有自己的配方等等
后面我们讲到方块实体
的时候,也会来写我们自己方块实体的配方
和前面的战利品列表一样,我们直接来看原版的那些配方文件
那些配方文件也是放在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 }
|
type
是minecraft:crafting_shaped
,即有序合成
category
是配方分类,在工作台中,游戏会根据这个将合成物分到相应的标签页,
这里是equipment
,即装备,还有misc
杂项、building
建筑方块等等
下面的key
和pattern
可以一起来看,pattern
是合成模式,有序合成
需要遵循这个模式才能进行合成,
这个模式中填的就是一些字符
,而这些字符对应的就是key
中的物品
值得注意的是,patter
n中,每一行的字符数量必须相同
,否则游戏无法正确读取,
我们可以拿另一个配方来看看
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" } }
|
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
| { "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" }
|
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
| { "type": "minecraft:blasting", "category": "misc", "cookingtime": 100, "experience": 0.7, "group": "copper_ingot", "ingredient": { "item": "minecraft:raw_copper" }, "result": "minecraft:copper_ingot" }
|
type
是minecraft: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" }
|
形式上和熔炉、高炉的差不多
type
是minecraft: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" }
|
type
是minecraft: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 }
|
再如甜菜
合成糖
,这样甜菜就成为糖料作物了
测试
那么现在,我们就可以进入游戏去测试一下
由于我们没有写进度文件,所有只有我们自己手动合成上面写的那些东西时,
才会在右上角弹出配方的解锁提示