ModderDojo 2016: Adding a Crafting Recipe in Scriptcraft

craftdiamonds

In a post from last year, we saw how to create crafting recipes in Java modding:

https://cdathenry.wordpress.com/2014/01/19/modderdojo-java-modding-6-creating-our-first-mod-adding-a-crafting-recipe/

It is also possible to do the same thing in Scriptcraft. Here is the code for a dirt to diamonds recipe in Scriptcraft:

Note: write the code in a file called something like “recipe1.js” and put it in the same folder as your other Scriptcraft mod (a sub-folder of scriptcraft – plugins). Note that this is the entire code – it does NOT go inside a function definition.

[code language="javascript"]
// Scriptcraft recipe for dirt to diamonds
var recipes = require('recipes');
var items = require('items'); 

// Here is the recipe: result from ingredients in a shape.
var dirt2diamond = {result: items.diamondBlock(10),
                    ingredients: {D: items.dirt(1)},
                    shape: [ ' D ',
                             'D D',
                             ' D ' ]};

// add the recipe to  the server
recipes.add(dirt2diamond);
[/code]

The code is reasonably easy to understand, I think. The result is a stack of 10 diamondBlock items, there is a single ingredient which is a dirt block that we indicate with a variable ‘D’, and they are arranged in a diamond shape. I have put in extra line breaks to make the shape clearer, but this is not necessary.

You can have more than one ingredient. Here is another example:

[code language="javascript"]
// A second recipe:
// diamond block made with a diagonal line of 2 dirt , 1 cobblestone, and 2 dirt
var recipe2 = {result: items.diamondBlock(1),
               ingredients: {D: items.dirt(2), C: items.cobblestone(1)},
               shape: [ 'D  ', ' C ', '  D' ]};
// add the recipe to  the server
recipes.add(recipe2);
[/code]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s