# RecipeInventory

`com.jsmacrosce.jsmacros.client.api.classes.inventory.RecipeInventory`

**Since:** 1.8.4

Base API for recipe-book screens, exposing their input dimensions, cells, output, and recipe-book entries.  

Reported dimensions vary by container. The player's inventory screen reports zero width and
height despite having a 2-by-2 crafting grid; consequently [getInput()](#com.jsmacrosce.jsmacros.client.api.classes.inventory.RecipeInventory_getInput-) returns an
empty array there. Read those cells individually with [getInput(int, int)](#com.jsmacrosce.jsmacros.client.api.classes.inventory.RecipeInventory_getInput-int-int-). Other
recipe-book screens provide their own grid dimensions and cell implementations.  

The recipe-book visibility and entries are accessed through [isRecipeBookOpened()](#com.jsmacrosce.jsmacros.client.api.classes.inventory.RecipeInventory_isRecipeBookOpened-),  
[toggleRecipeBook()](#com.jsmacrosce.jsmacros.client.api.classes.inventory.RecipeInventory_toggleRecipeBook-), [setRecipeBook(boolean)](#com.jsmacrosce.jsmacros.client.api.classes.inventory.RecipeInventory_setRecipeBook-boolean-), and [getRecipes(boolean)](#com.jsmacrosce.jsmacros.client.api.classes.inventory.RecipeInventory_getRecipes-boolean-).  
```js
const inv = Player.openInventory();  
if (inv instanceof Inventories.Crafting) {
  const grid = inv.getInput();  
  for (let x = 0; inv.getCraftingWidth() > x; x++) {
    for (let z = 0; inv.getCraftingHeight() > z; z++) {
      if (!grid[x][z].isEmpty()) {
        Chat.log(`cell ${x},${z} holds ${grid[x][z].getItemId()}`);  
      }
    }
  }
}
```

Available in scripts as `Inventories.Recipe`.

## Type Parameters

- `T`: the recipe-book screen type wrapped by this inventory

## Methods

### getCategory {#com.jsmacrosce.jsmacros.client.api.classes.inventory.RecipeInventory_getCategory-}

```js
getCategory(): String
```

Returns the name of the recipe-book category associated with this container.

**Returns:** the category name

**Since:** 1.8.4

### getCraftableRecipes {#com.jsmacrosce.jsmacros.client.api.classes.inventory.RecipeInventory_getCraftableRecipes-}

```js
getCraftableRecipes(): List<RecipeHelper>
```

Returns recipes reported craftable using the player's inventory and this container's input
slots. The list may be empty.

**Returns:** recipes reported craftable from the available items; may be empty

**Since:** 1.3.1

### getCraftingHeight {#com.jsmacrosce.jsmacros.client.api.classes.inventory.RecipeInventory_getCraftingHeight-}

```js
getCraftingHeight(): int
```

Returns the input-grid height reported by this container. The player's inventory screen
reports zero despite having a 2-by-2 crafting grid.

**Returns:** the reported input-grid height

**Since:** 1.8.4

### getCraftingSlotCount {#com.jsmacrosce.jsmacros.client.api.classes.inventory.RecipeInventory_getCraftingSlotCount-}

```js
getCraftingSlotCount(): int
```

Returns the number of input slots reported by this container, which need not match the
product of the reported grid dimensions.

**Returns:** the reported input-slot count

**Since:** 1.8.4

### getCraftingWidth {#com.jsmacrosce.jsmacros.client.api.classes.inventory.RecipeInventory_getCraftingWidth-}

```js
getCraftingWidth(): int
```

Returns the input-grid width reported by this container. The player's inventory screen
reports zero despite having a 2-by-2 crafting grid.

**Returns:** the reported input-grid width

**Since:** 1.8.4

### getInput {#com.jsmacrosce.jsmacros.client.api.classes.inventory.RecipeInventory_getInput-int-int-}

```js
getInput(int x, int z): ItemStackHelper
```

Returns an input cell. Coordinates are zero-based, with `x` increasing left to right
and `z` top to bottom. The player's inventory screen accepts its 2-by-2 cell
coordinates even though its reported dimensions are zero.

**Parameters:**
- `x`: zero-based column, increasing left to right
- `z`: zero-based row, increasing top to bottom

**Returns:** the item in the selected input cell

**Since:** 1.8.4

### getInput {#com.jsmacrosce.jsmacros.client.api.classes.inventory.RecipeInventory_getInput-}

```js
getInput(): ItemStackHelper[][]
```

Returns input cells in an array indexed by column, then row. Its dimensions are the
reported width and height, so it is empty when either dimension is zero.

**Returns:** the grid as `[column][row]`

**Since:** 1.8.4

### getInputSize {#com.jsmacrosce.jsmacros.client.api.classes.inventory.RecipeInventory_getInputSize-}

```js
getInputSize(): int
```

Returns the product of the container-reported input width and height.

**Returns:** the product of [getCraftingWidth()](#com.jsmacrosce.jsmacros.client.api.classes.inventory.RecipeInventory_getCraftingWidth-) and [getCraftingHeight()](#com.jsmacrosce.jsmacros.client.api.classes.inventory.RecipeInventory_getCraftingHeight-)

**Since:** 1.8.4

### getOutput {#com.jsmacrosce.jsmacros.client.api.classes.inventory.RecipeInventory_getOutput-}

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

Returns the item in this container's result slot.

**Returns:** the item in the container's result slot

**Since:** 1.8.4

### getRecipes {#com.jsmacrosce.jsmacros.client.api.classes.inventory.RecipeInventory_getRecipes-boolean-}

```js
getRecipes(boolean craftable): List<RecipeHelper>
```

Returns entries in this screen's recipe-book tabs, optionally limited to entries craftable
from the player's inventory and this container's crafting slots.

**Parameters:**
- `craftable`: whether to include only entries reported craftable from the player's
                 inventory and this container's crafting slots

**Returns:** entries in the screen's recipe-book tabs, filtered by craftability when requested;  
        the list is non-null and may be empty

**Since:** 1.8.4

### isRecipeBookOpened {#com.jsmacrosce.jsmacros.client.api.classes.inventory.RecipeInventory_isRecipeBookOpened-}

```js
isRecipeBookOpened(): boolean
```

Returns whether this container's recipe-book widget is visible; if it has no widget,  
returns `false`.

**Returns:** `true` if the recipe book is visible, `false` otherwise.

**Since:** 1.8.4

### setRecipeBook {#com.jsmacrosce.jsmacros.client.api.classes.inventory.RecipeInventory_setRecipeBook-boolean-}

```js
setRecipeBook(boolean open): void
```

Sets this container's recipe-book widget visibility when its screen is currently open.  
Does nothing if the screen is not open, has no widget, or already has the requested state.

**Parameters:**
- `open`: whether the recipe book should be showing when this returns

**Since:** 1.8.4

### toggleRecipeBook {#com.jsmacrosce.jsmacros.client.api.classes.inventory.RecipeInventory_toggleRecipeBook-}

```js
toggleRecipeBook(): void
```

Toggles this container's recipe-book widget when its screen is currently open. Does
nothing if the screen is not open or has no recipe-book widget.

**Since:** 1.8.4
