Skip to content
jellysnake edited this page Dec 2, 2017 · 2 revisions

Introduction

BasicCrafting provides a simple way for multiple crafting flavours to exist in parallel, all with similar ways for a Content Dev to add recipes. It's intended to be very easy to use and with the ability to support many different types of recipes within the same basic framework.

Using ListCrafting

ListCrafting is the default flavour of crafting. It is similar to Terraria style where all that is needed is the inputs in an inventory and the recipe can be crafted. It currently also provides a widget capable of displaying and crafting all recipes in a category.

Using ingredient names

Ingredient Names Can Be Used By Any Flavour, Not Just ListCrafting
Often times an item could have multiple names and be used in multiple different recipes. Eg, a recipe for a door should be able to use any type of wood. A module that adds "OakWood" should automatically have that as an ingredient for a door. As should "BirchWood", "ElmWood" or any other types.
This is achieved by using Ingredient Names. These are alternative names that can be specified on an item, eg all the above woods could have an alternative name of "Wood". This would allow a recipe to simply use "wood" as an input rather than list each variety.

Ingredient names are specified by adding a CraftingIngredientComponent to the prefab. This component contains a list of other names that can refer to that item. For blocks the Category field is used. Both function the same way. The CraftingIngredientComponent as a single field, "ingredientIds". This field (and "categories" for blocks) contains a list of Strings, each string being an alternative name.
This is an example for an Axe.

"CraftingIngredient": {
  "ingredientIds": [
    "tool",
    "weapon"
  ]
}

And this is an example for a GoldOre block

"categories": [
  "mineral",
  "rawMetal",
  "stone"
],

Adding a new recipe

Recipes are added by placing a ListRecipesComponent onto a prefab. This component contains a list of recipes and a list of categories to place these recipes in.

"ListRecipes": {
  "categories": [
    ...
  ],
  "recipes": {
    ...
  }
}

All the items in categories are just strings. The categories section from CommonEdibleFlora looks like this

"categories": [
  "InHand",
  "Seeds"
]

All the recipes in that component will be placed into those categories. Recipes are then shown in the UI by giving the widget a category and it will then display all recipes in that category.
The recipes section is a list of recipes. Each recipe looks like this:

"OutputItem": {
  "inputs": {
    "InputOne": 1,
    "InputTwo": 1,
    "InputThree": 1,
    ...
  },
  "outputCount": 1
},

"OutputItem" is the result that the crafting recipe will try to make. It should be either an Item or a Block and should be unique. The easiest way to make sure an item is unique is to use the Specific name, ie "Core:Dirt" not "Dirt".
The inputs can either be a Specific name(the full Module:Item), Simple name (just Item) or an Ingredient name (one listed in the CraftingIngredientComponent). Each level will match a wider range of items, additionally if there is more than one option found the recipe view will cycle through the options.
This is an example recipe from CommonEdibleFlora

"CommonEdibleFlora:Blackberry": {
  "inputs": {
    "CommonEdibleFlora:OrangeSeed": 1,
    "CommonEdibleFlora:AppleSeed": 1
  },
  "outputCount": 1
}

As you can see both ingredients use the Specific names to ensure that only that only those two items are valid inputs for the recipe. They could also easily use simply "OrangeSeed" and "AppleSeed" and then items from any module that has those names could be used as input. Likewise, having just "Seed" would allow anything that has been marked as a seed through a CraftingIngredientComponent.

Whilst the output item must be unique it's viable and recommended to use the most appropriate level of restriction for the input names.

Adding a new crafting flavour

Adding a new crafting flavour requires adding a new Recipe, RecipeComponent and a CraftingManager. TODO: Write guide for adding a flavour

Adding a new Recipe

Adding a new RecipeComponent

Adding a new CraftingManager