有序合成配方中材料的排序很重要,它们需要以特定的形状进行合成。
下面这个例子是合成桶的配方,其中铁锭需要以正确的顺序排列才能够合成。

虽然有序合成配方需要遵循特定的模式,但并不总是需要放在确定的位置上。
使用铁桶作为例子,下列两种配方都是有效的铁桶合成方式,即使物品放在不同的位置上。

Bucket With Ingots in the top two rows

Bucket with Ingots in the bottom two rows

该效果是通过不填满完整的3*3网格来实现的,下面是一个添加像这样的配方的例子。

添加有序合成配方

Link to 添加有序合成配方

下面这个方法用于在游戏中添加一个有序合成配方。

一个有序配方的基础语法如下:

ZenScript
Copy
// craftingTable.addShaped(recipeName as string, 
//      output as IItemStack,
//      ingredients as IIngredient[][], 
//      recipeFunction as @optional RecipeFunctionMatrix);

The optional RecipeFunctionMatrix at the end of the method is only needed for advanced recipe where the output changes depending on the input, an example being transfering NBT data from one of the input ingredients to the output item.

In general, most of your recipes are not going to be using the function, but it is there if you need it.

The recipeName has some restrictions that should be kept in mind: 1) The name you provide is the "path" value of the name of the recipe, all recipes added through CraftTweaker will have the crafttweaker modid as part of the name.
For example, if you provide "boat" as the name, the full recipe name will be crafttweaker:boat. 2) It needs to be unique, using a non-unique recipe name will cause your recipe to replace the previous recipe. 3) It cannot contain spaces or colons (:). 4) It must be all lowercased. 5) It cannot start with "autogenerated/" as it is a reserved CraftTweaker folder.

For the output, something to note is that it has to be an IItemStack, passing in an IIngredient will not work, so using <tag:items:minecraft:wool> or <item:minecraft:diamond> | <item:minecraft:dirt> will not work as they are both IIngredients, but using <item:minecraft:diamond> is valid and will work.

下面是一个关于如何添加一有序合成配方使得三块泥土合成钻石的例子,其中左上角,中间,右上角各一个泥土(类似于铁桶配方中铁锭的摆放方式)

For a recipe like this, you don't need the recipe function, so it is simply left out.

注意这个方法,因为我们只使用了2行, 所以其配方可能正好像上面做出的桶配方的例子。

ZenScript
Copy
craftingTable.addShaped("dirt_bucket_to_diamond", <item:minecraft:diamond>, [
    [<item:minecraft:dirt>, <item:minecraft:air>, <item:minecraft:dirt>], 
    [<item:minecraft:air>, <item:minecraft:dirt>, <item:minecraft:air>]]);

下一个有序合成配方是你可以强制该配方需要物品以特定方式摆放的一个例子,即便该配方只使用两行物品,如上面的桶配方。

该配方将只在左下方的位置接受单个苹果,并将输出一只箭矢。

因为我们将 item:minecraft:air 放在了其他位置,所以他只能接受左下方的苹果。

ZenScript
Copy
craftingTable.addShaped("apple_to_arrow", <item:minecraft:arrow>, [
    [<item:minecraft:air>, <item:minecraft:air>, <item:minecraft:air>], 
    [<item:minecraft:air>, <item:minecraft:air>, <item:minecraft:air>], 
    [<item:minecraft:apple>, <item:minecraft:air>, <item:minecraft:air>]]);

下一个有序合成配方是一个如何使用RecipeFunction来根据输入改变输出的例子。

当钻石被放入左上方并且一个苹果被放进中心时,该配方将会输出一块泥土。然而,如果输入苹果的名称为“超级苹果”,它将产生8块泥土。

您从输入中引用物品的方式是通过输入数组中的位置索引,因此由于苹果处于第一行第一列,我们使用[1][1]来指代它,即使配方是2*2的并且苹果也可能不处于制作网格的中心槽位。

ZenScript
Copy
craftingTable.addShaped("diamond_and_apples_to_dirt", <item:minecraft:dirt>, [
    [<item:minecraft:diamond>, <item:minecraft:air>], 
    [<item:minecraft:air>, <item:minecraft:apple>]],
(usualOut as IItemStack, inputs as IItemStack[][]) => {

    if <item:minecraft:apple>.withTag({display: {Name: "{\"text\":\"Super Apple\"}"}}).matches(inputs[1][1]) {
        return usualOut * 8;
    }

    return usualOut;

});