原版配方
约 1168 字大约 4 分钟
2024-09-26
- 因为配方事件是一个服务器事件所以我们需要在 ServerEnents 的环境下进行编写 JS 脚本。
工作台配方
- 工作台配方总共分为两种:
- 一种是有序配方(
shaped) - 一种是无序配方(
shapeless)
- 一种是有序配方(
有序配方(shaped)
- 配方说明:原料在工作台的GUI中以某种确定的摆放方式进行合成的合成。
基本语法:
ServerEvents.recipes((event) => {
event.recipes.kubejs.shaped(result, pattern, key, category?);
event.recipes.minecraft.crafting_shaped(result, pattern, key, category?);
});提示
其实 event.recipes.kubejs.shaped() 还可以简写为 event.shaped() ,但我 不推荐 使用语句更短的那一种写法。
无序配方(shapeless)
- 配方说明:原料在工作台的GUI中无需以确定的摆放方式进行的合成。
基本语法:
ServerEvents.recipes((event) => {
event.recipes.kubejs.shapeless(result, ingredients, category?);
event.recipes.minecraft.crafting_shapeless(result, ingredients, category?);
});配方修饰
注
添加无序/有序合成时建议使用 event.recipes.kubejs() 而不是 event.recipes.minecraft(),因为后者不支持配方修饰。这也是我之前推荐使用 event.recipes.kubejs() 的原因。
替换原料(replaceIngredient)
- 配方说明:合成后将原料进行替换。
- 示例:木剑 + 2x铁锭 => 铁剑,铁锭将变为橡木木板。
ServerEvents.recipes(event => {
event.recipes.kubejs.shaped(
Item.of('minecraft:iron_sword', '{Damage:0}'),
[
' A',
' A ',
'B '
],
{
A: 'minecraft:iron_ingot',
B: Item.of('minecraft:wooden_sword', '{Damage:0}')
}
).replaceIngredient('minecraft:iron_ingot', 'minecraft:oak_planks')
})损伤原料(damageIngredient)
- 配方说明:合成后将会使原料的耐久度减少。
- 示例:木剑 + 铁锭 => 10铁粒,扣除木剑1点耐久
未指定扣除的耐久时
ServerEvents.recipes(event => {
event.recipes.kubejs.shapeless(
'10x minecraft:iron_nugget',
[
Item.of('minecraft:wooden_sword', '{Damage:0}'),
'minecraft:iron_ingot'
]
).damageIngredient(Item.of('minecraft:wooden_sword', '{Damage:0}'))
})指定了扣除的耐久时
ServerEvents.recipes(event => {
event.recipes.kubejs.shapeless(
'10x minecraft:iron_nugget',
[
Item.of('minecraft:wooden_sword', '{Damage:0}'),
'minecraft:iron_ingot'
]
).damageIngredient(Item.of('minecraft:wooden_sword', '{Damage:0}'), 1)
})保持原料(keepIngredient)
- 配方说明:合成后将会保持原料不会消失。
- 示例:铁镐 + 铁矿石 => 2x粗铁,铁镐不会消失。
ServerEvents.recipes(event => {
event.recipes.kubejs.shapeless(
'2x minecraft:raw_iron',
[
Item.of('minecraft:iron_pickaxe', '{Damage:0}'),
'minecraft:iron_ore'
]
).keepIngredient(Item.of('minecraft:iron_pickaxe', '{Damage:0}'))
})熔炉、高炉、烟熏炉配方
烧炼(smelting)
- 配方说明:将原料熔炼(或烧制或烹饪)为产物。
ServerEvents.recipes((event) => {
event.recipes.minecraft.smelting(result, ingredient, xp?, cookingTime?, category?);
});高温烧炼(blasting)
- 配方说明:将原料熔炼(或烧制)为产物。
ServerEvents.recipes((event) => {
event.recipes.minecraft.blasting(result, ingredient, xp?, cookingTime?, category?);
});烟熏(smoking)
- 配方说明:将原料烹饪为产物。
ServerEvents.recipes((event) => {
event.recipes.minecraft.smoking(result, ingredient, xp?, cookingTime?, category?);
});提示
熔炉的特殊之处:在熔炉之中可以制作以上三种配方,但是高炉只能制作高温烧炼(blasting)配方、烟熏炉只能制作烟熏(smoking)配方。
营火配方
营火烹饪(campfire_cooking)
- 配方说明:使用营火进行烹饪。
ServerEvents.recipes((event) => {
event.recipes.minecraft.campfire_cooking(result, ingredient, xp?,cookingTime?, category?);
});锻造台配方
升级(smithing_transform)
- 配方说明:例如使钻石装备升级为下界合金装备。
Minecraft 1.20 +
ServerEvents.recipes((event) => {
event.recipes.minecraft.smithing_transform(result, template, base, addition);
});纹饰(smithing_trim)
- 配方说明:给盔甲附着纹饰。
ServerEvents.recipes((event) => {
event.recipes.minecraft.smithing_trim(template, base, addition);
});切石机
切石(stonecutting)
- 配方说明:使用切石机合成。
ServerEvents.recipes(event => {
event.recipes.minecraft.stonecutting(result, ingredient);
})参数解释
result配方结果,需要填写一个$ItemStack$$Type类型,详细见 ItemStack。pattern配方图案,需要填写一个$List$$Type<(string)>类型。众所周知,我的世界的工作台的GUI是一个9*9的格子,因此我们使用数组来表示这个9*9的格子。所以说图案是一个包含三个字符串的数组,每个字符串有三个字符。
提示
你可以在九个字符中填入空格(等同于该槽位没有物品)、特殊符号、大小写字母等。
[
'AAA',
'B C',
'D#A'
]key配方图案字符代表的原料,需要填写一个$Map$$Type<(character), ($Ingredient$$Type)>类型,这是一个Map类型的字段,因此它是一个键值对。
{
A: $Ingredient$$Type,
B: 'minecraft:dirt',
C: 'minecraft:air', // 等同于直接在 pattern 中直接填空格
D: '#ingot/iron', // 也可以使用标签
#: Item.of('minecraft:iron_sword', '{Damage:0}')
}ingredients配方原料,需要填写一个$List$$Type<($Ingredient$$Type)>类型,可以填入很多很多个字符串。xp配方经验,需要填写一个float类型,配方完成后会给予玩家相应的经验值,这是一个可选参数。cookingTime熔炼(或烧制或烹饪)时间,需要填入一个$TickDuration$$Type类型,这是一个可选参数。template锻造模板base输入物品addition升级材料category配方种类,需要填写一个$CraftingBookCategory$$Type类型,该值决定该配方出现在配方书中的哪个标签栏,这是一个可选的参数。
提示
这是一些可以填写的字段:building(建筑),redstone(红石),equipment(装备),misc(杂项)。