Skip to content

RecipeHelper ​

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

Since1.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 ​

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 ​

canCraft(): booleanSince1.8.4#
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.
canCraft(int amount): booleanSince1.8.4#
Tests whether 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.

craft ​

craft(boolean craftAll): RecipeHelperSince1.3.1#
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.

getCraftableAmount ​

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

getGroup ​

getGroup(): StringSince1.8.4#
Returns this recipe's recipe-book category identifier.
Returns: the category identifier.

getIngredients ​

getIngredients(): List<List<ItemStackHelper>>Since1.8.3#
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.

getOutput ​

getOutput(): ItemStackHelperSince1.3.1#
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.

toString ​

toString(): String#
Returns a diagnostic representation containing the display entry's identifier.
Returns: a diagnostic representation of the recipe display entry.