Skip to content

RecipeInventory ​

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

Since1.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() returns an empty array there. Read those cells individually with 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(),
toggleRecipeBook(), setRecipeBook(boolean), and 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 ​

getCategory(): StringSince1.8.4#
Returns the name of the recipe-book category associated with this container.
Returns: the category name

getCraftableRecipes ​

getCraftableRecipes(): List<RecipeHelper>Since1.3.1#
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

getCraftingHeight ​

getCraftingHeight(): intSince1.8.4#
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

getCraftingSlotCount ​

getCraftingSlotCount(): intSince1.8.4#
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

getCraftingWidth ​

getCraftingWidth(): intSince1.8.4#
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

getInput ​

getInput(int x, int z): ItemStackHelperSince1.8.4#
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
getInput(): ItemStackHelper[][]Since1.8.4#
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]

getInputSize ​

getInputSize(): intSince1.8.4#
Returns the product of the container-reported input width and height.
Returns: the product of getCraftingWidth() and getCraftingHeight()

getOutput ​

getOutput(): ItemStackHelperSince1.8.4#
Returns the item in this container's result slot.
Returns: the item in the container's result slot

getRecipes ​

getRecipes(boolean craftable): List<RecipeHelper>Since1.8.4#
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

isRecipeBookOpened ​

isRecipeBookOpened(): booleanSince1.8.4#
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.

setRecipeBook ​

setRecipeBook(boolean open): voidSince1.8.4#
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

toggleRecipeBook ​

toggleRecipeBook(): voidSince1.8.4#
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.