# RecipeHelper

`com.jsmacrosce.jsmacros.client.api.helper.inventory.RecipeHelper`

**Since:** 1.3.1

Describes a recipe's inputs and output, and checks or requests crafting for the current player.  
Recipe helpers are returned by recipe inventories such as `RecipeInventory.getRecipes()`.  
```js
function affordable(recipes) {
  for (let i = 0; i !== recipes.size(); i += 1) {
    const recipe = recipes.get(i);  
    const times = recipe.getCraftableAmount();  
    if (times > 0) {
      Chat.log(`${recipe.getOutput().getItemId()} can be made ${times} times`);  
    }
  }
}
```

## Constructors

### new RecipeHelper {#com.jsmacrosce.jsmacros.client.api.helper.inventory.RecipeHelper_constructor-RecipeDisplayEntry-int-}

```js
new RecipeHelper(RecipeDisplayEntry base, int syncId)
```

Wraps a recipe display entry and records the menu synchronization ID used by craft requests.

**Parameters:**
- `base`: the raw recipe display entry to wrap
- `syncId`: the menu synchronization ID used by craft requests

## Methods

### canCraft {#com.jsmacrosce.jsmacros.client.api.helper.inventory.RecipeHelper_canCraft-}

```js
canCraft(): boolean
```

Tests whether one craft is possible using the player's inventory, plus the crafting slots
when a recipe-book screen is open.

**Returns:** `true` if one craft is possible, `false` otherwise.

**Since:** 1.8.4

### canCraft {#com.jsmacrosce.jsmacros.client.api.helper.inventory.RecipeHelper_canCraft-int-}

```js
canCraft(int amount): boolean
```

Tests whether [getCraftableAmount()](#com.jsmacrosce.jsmacros.client.api.helper.inventory.RecipeHelper_getCraftableAmount-) is at least `amount`; zero and negative
amounts therefore return `true`.

**Parameters:**
- `amount`: the minimum number of crafts required

**Returns:** `true` when the computed craftable amount is at least `amount`.

**Since:** 1.8.4

### craft {#com.jsmacrosce.jsmacros.client.api.helper.inventory.RecipeHelper_craft-boolean-}

```js
craft(boolean craftAll): RecipeHelper
```

Requests crafting through the matching open container screen, or the player inventory when
no screen is open. Returns this helper. If its originating menu is not open, throws an
`AssertionError`.

**Parameters:**
- `craftAll`: whether to craft as many times as the ingredients allow rather than once.

**Returns:** this recipe, for chaining.

**Since:** 1.3.1

### getCraftableAmount {#com.jsmacrosce.jsmacros.client.api.helper.inventory.RecipeHelper_getCraftableAmount-}

```js
getCraftableAmount(): int
```

Counts how many times the recipe's requirements can be met from the player's inventory,  
including crafting slots when a recipe-book screen is open. This calculation does not craft
the recipe.

**Returns:** the number of crafts allowed by the available ingredients.

**Since:** 1.8.4

### getGroup {#com.jsmacrosce.jsmacros.client.api.helper.inventory.RecipeHelper_getGroup-}

```js
getGroup(): String
```

Returns this recipe's recipe-book category identifier.

**Returns:** the category identifier.

**Since:** 1.8.4

### getIngredients {#com.jsmacrosce.jsmacros.client.api.helper.inventory.RecipeHelper_getIngredients-}

```js
getIngredients(): List<List<ItemStackHelper>>
```

Each outer-list entry is a recipe slot; its inner list contains the alternative item stacks
accepted for that slot. A recipe with no declared ingredients returns an empty list.

**Returns:** the ingredient slots and their accepted item stacks; empty when none are declared.

**Since:** 1.8.3

### getOutput {#com.jsmacrosce.jsmacros.client.api.helper.inventory.RecipeHelper_getOutput-}

```js
getOutput(): ItemStackHelper
```

Returns the first result as a stack, resolving display data using the loaded world. Its count
is the output count for one craft.

**Returns:** the first result stack.

**Since:** 1.3.1

### toString {#com.jsmacrosce.jsmacros.client.api.helper.inventory.RecipeHelper_toString-}

```js
toString(): String
```

Returns a diagnostic representation containing the display entry's identifier.

**Returns:** a diagnostic representation of the recipe display entry.
