> For the complete documentation index, see [llms.txt](https://docs.sparkframework.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sparkframework.dev/documentation/developer-guide/plugins/crafting/api.md).

# API

**Assembly:** `Spark.Crafting` **Interface:** `ICraftingPlugin` **Implementation:** `CraftingPlugin`

## Interface

```csharp
public interface ICraftingPlugin
{
    IReadOnlyList<CraftingRecipeEntry> GetAllRecipes();
    CraftingRecipeEntry FindRecipeById(string recipeId);
    CraftingRecipeEntry FindRecipeForItem(ItemEntry craftedItem);
    IReadOnlyList<CraftingRecipeEntry> FindRecipesForItem(ItemEntry craftedItem);
}
```

## Methods

### GetAllRecipes

```csharp
IReadOnlyList<CraftingRecipeEntry> GetAllRecipes()
```

Returns all crafting recipes in the database.

### FindRecipeById

```csharp
CraftingRecipeEntry FindRecipeById(string recipeId)
```

Returns a specific recipe by ID, or `null` if not found.

### FindRecipeForItem / FindRecipesForItem

```csharp
CraftingRecipeEntry FindRecipeForItem(ItemEntry craftedItem)
IReadOnlyList<CraftingRecipeEntry> FindRecipesForItem(ItemEntry craftedItem)
```

Find recipes that produce a given item. `FindRecipeForItem` returns the first match; `FindRecipesForItem` returns all matches.

## CraftingRecipeEntry

Extends `SparkDatabaseEntry`. Defines a crafting recipe.

| Field                | Type                        | Description                |
| -------------------- | --------------------------- | -------------------------- |
| `recipeCategory`     | CraftingRecipeCategoryEntry | Recipe category            |
| `craftedItem`        | ItemEntry                   | Item produced              |
| `craftDuration`      | float                       | Time to craft (seconds)    |
| `autoLearn`          | bool                        | Automatically known        |
| `requiredComponents` | List\<RecipeComponent>      | Materials needed           |
| `onCraftTriggers`    | List\<TriggerEntry>         | Triggers executed on craft |

### RecipeComponent

| Field    | Type      | Description       |
| -------- | --------- | ----------------- |
| `item`   | ItemEntry | Required material |
| `amount` | int       | Quantity needed   |

## CraftingRecipeCategoryEntry

Extends `SparkDatabaseEntry`. Groups recipes into categories for UI organization.

## Events

| Event                 | Description                     |
| --------------------- | ------------------------------- |
| `RecipeLockedEvent`   | Recipe locked for a character   |
| `RecipeUnlockedEvent` | Recipe unlocked for a character |
| `RecipeCraftedEvent`  | Recipe successfully crafted     |

## Commands

| Command            | Fields                                                 | Description     |
| ------------------ | ------------------------------------------------------ | --------------- |
| `CraftItemCommand` | `crafter` (GameObject), `recipe` (CraftingRecipeEntry) | Execute a craft |

## Save Data

### CraftingSaveData

Extends `SaveDataEntry`. Tracks which recipes are unlocked.

**Methods:**

```csharp
bool IsRecipeUnlocked(string recipeId)
void UnlockRecipe(string recipeId)
void LockRecipe(string recipeId)
void ClearUnlockedRecipes()
```

On `InitializeDefaults()`, all recipes with `autoLearn = true` are automatically unlocked.

## Usage

```csharp
var crafting = Spark.GetPlugin<ICraftingPlugin>();
if (crafting != null)
{
    // List all recipes
    var recipes = crafting.GetAllRecipes();

    // Find a specific recipe
    var recipe = crafting.FindRecipeById("iron_sword_recipe");

    // Find recipes that produce an item
    var swordRecipes = crafting.FindRecipesForItem(ironSwordEntry);

    // Craft via command
    Spark.Network?.ExecuteCommand(new CraftItemCommand
    {
        crafter = playerObject,
        recipe = recipe
    });
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.sparkframework.dev/documentation/developer-guide/plugins/crafting/api.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
