Skip to content

Crafting Recipes with RecipeBuilders

Adding Recipes with Builders

Crafting also has a RecipeBuilder. If you don't know what a builder is, check this out!

You start the builder chain with either shapedBuilder() or shapelessBuilder(). This determines the kind of recipe you want to add.

groovy
crafting.shapedBuilder()
crafting.shapelessBuilder()

Then you call additional methods onto the builder (.name(), .replace(), etc), to build up the end result. See the examples below for a complete picture.

Set the recipe name (optional):

name(String name)

If not provided, a recipe name will be autogenerated for you.

Set the recipe output (required):

groovy
output(ItemStack item)

Set the recipe function (optional):

recipeFunction(Closure<ItemStack> recipeFunction)

See the Recipe Function and Action page for more details.

Set the recipe action (optional):

recipeFunction(Closure<Void> recipeAction)

See the [Recipe Function and Action page] for more details.

TODO

This page is not yet created!

Set the recipe to replace others (optional):

replace()

See the Crafting page for details about these.

Set the recipe to replace others by name (optional):

replaceByName()

See the Crafting page for details about these. It functions the same as the one above, except that it matches the provided recipe name.

Set the recipe to allow the grid to be mirrored (optional, shaped only):

groovy
mirrored()
mirrored(boolean mirrored) // (1)!
  1. Choose whether the recipe is mirrored or not, default false

Creating the recipe's layout (required, shaped only):

groovy
matrix(String... matrix)
shape(String... matrix) // does the same thing as matrix()

// to input a matrix in the style of non-builder shaped addition
matrix(List<List<IIngredient>> matrix)
shape(List<List<IIngredient>> matrix)

Matching ingredients to the recipe layout (required, shaped only):

groovy
key(String c, IIngredient ingredient) // (1)!
  1. Please see the examples below to better understand how this works

Adding inputs to the recipe (required, shapeless only):

groovy
input(IIngredient ingredient)
input(IIngredient... ingredients)
input(Collection<IIngredient> ingredients)

Registering the recipe (required):

groovy
register()

Reading the above makes this seem quite complicated. We promise it's not!

Shaped

Example

groovy
// Shaped Recipes
crafting.shapedBuilder()                    // create a new shaped recipe
        .name('balanced_clay')              // name the recipe 'balanced_clay'
        .output(item('minecraft:clay') * 32)      // output 32 clay
        .matrix('NIN',                      // create the layout for the recipe
                'DSD',                      // each character represents a slot
                'NIN')
        .key('N', item('minecraft:nether_star'))  // everywhere there is an 'N' in the layout, use a nether star
        .key('I', ore('ingotIron'))               // all 'I' characters are iron ingots
        .key('D', item('minecraft:diamond'))      // all 'D' characters are diamonds
        .key('S', ore('stone'))                   // all 'I' characters are stone
        .register()                         // register the recipe

Shapeless

Example

groovy
// Shapeless Recipes
crafting.shapelessBuilder()                                     // add a new shapeless recipe
        .name('balanced_clay_v3')                               // name the recipe 'balanced_clay_v3'
        .output('minecraft:clay' * 2)                           // output 2 clay
        .input('minecraft:iron_ingot')                          // add an iron ingot to the inputs
        .input('minecraft:iron_ingot')                          // add a second iron ingot to the inputs
        .input('minecraft:gold_nugget', 'minecraft:diamond')    // add a gold nugget and a diamond to the inputs
        .register()

Empty Spaces

INFO

If you want the slot to be empty, don't use a key and null, but instead just use a space!

Example

The matrix should look like this:

groovy
crafting.shapedBuilder()
        .name('balanced_clay_v2')
        .output(item('minecraft:clay') * 64)
        .matrix(' B ',                      // use a space for an empty slot
                'X X')                      // (1)!
        .key('B', item('minecraft:glass_bottle'))
        .key('X', item('minecraft:gold_nugget'))
        .register()
  1. You can omit rows and columns for smaller recipes - this one's 3x2. Just make sure it's not jagged (different lengths for each row/col).

贡献者

页面历史

© 2024 CleanroomMC. All Rights Reserved.