RecipeHelper
com.jsmacrosce.jsmacros.client.api.helper.inventory.RecipeHelper
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 wrapsyncId: the menu synchronization ID used by craft requests
Methods
canCraft
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.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
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
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
getIngredients
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
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.