RecipeInventory
com.jsmacrosce.jsmacros.client.api.classes.inventory.RecipeInventory
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
getCraftableRecipes
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
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
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
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
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 rightz: zero-based row, increasing top to bottom
Returns: the item in the selected input cell
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
Returns the product of the container-reported input width and height.
Returns: the product of getCraftingWidth() and getCraftingHeight()
getOutput
Returns the item in this container's result slot.
Returns: the item in the container's result slot
getRecipes
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
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
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
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.