Thursday, 5 February 2015

Recipes

Recipes are used for crafting and "smelting" (furnaces).

To jump straight to sample code, click here (MBE35).

Crafting Recipes

 For simple crafting recipes, there are two main types-
  • "Shaped", where the shape of the ingredients is important
  • "Shapeless", where it doesn't matter how the ingredients are arranged in the table
These are added in the init phase using GameRegistry.addShapedRecipe and .addShapelessRecipe, or alternatively using json files (no code required)

Shaped Recipe with metadata (Red Dye)
Shapeless Recipe - the yellow and blue dye can be placed anywhere
Shaped Recipe using json file

There are also "Ore" recipes, which are a Forge extension.
"Ores" are a way for mods to add blocks & items which are equivalent to vanilla blocks for crafting.
For example - an ore recipe which uses "logWood" will accept a log of spruce, oak, birch, pine, etc.  If your mod registers its balsawood log using OreDictionary.registerOre("logWood", BalsaWood), then your BalsaWood log will also be accepted in the recipe.

Shaped Ore recipe - "treeLeaves" ore will accept any kind of leaves
You can add your own complicated recipes (eg like Fireworks recipes) by implementing IRecipe and registering it using GameData.register_impl(myRecipe implements IRecipe);

Miscellaneous notes-

  • Vanilla recipes are automatically also valid when mirrored left-right.  If you don't want this, you can use a shaped ore recipe with false as the first parameter.
  • If you want the recipe to ignore an item's metadata / damage value, use OreDictionary.WILDCARD_VALUE for the damage value.
Non-mirrored recipes can be created using
ShapedOreRecipe (ItemCauldron, new Object[] {false, ...}

The steel sword recipe uses OreDictionary.WILDCARD_VALUE to ignore the sword's damage.
In contrast, the gold sword recipe only works on undamaged swords.

Furnace Recipes

Furnace recipes can be added using GameRegistry.addSmelting(..)
Extra fuel types can be added using GameRegistry.registerFuelHandler(...)

(1) cake smelts to charcoal, and (2) wheat can be used as fuel

Further reading

Wuppy29 recipes tutorial 1
Wuppy29 recipes tutorial 2
For good vanilla example recipes:
smelting - see FurnaceRecipes
shapeless recipes - see RecipeDyes
ore based recipes - OreDictionary
custom recipes - see RecipeFireworks



1 comment: