AnvilInventory
com.jsmacrosce.jsmacros.client.api.classes.inventory.AnvilInventory
Handle for an open anvil screen. Slots 0, 1, and 2 are the first input, second input, and result, respectively; getOutput() reads the current result rather than calculating it.
js
const inv = Player.openInventory();
if (inv instanceof Inventories.Anvil) {
Chat.log(`${inv.getLeftInput().getItemId()} + ${inv.getRightInput().getItemId()}`);
if (!inv.getOutput().isEmpty()) {
Chat.log(`result: ${inv.getOutput().getName()} for ${inv.getLevelCost()} levels`);
}
}Available in scripts as Inventories.Anvil.
Constructors
new AnvilInventory
new AnvilInventory(AnvilScreen inventory)#Wraps the supplied anvil screen and captures its menu and the current client player through Inventory's setup. This does not open or create a screen; scripts typically obtain a wrapper for the current screen through FPlayer.openInventory().
Parameters:
inventory: the anvil screen to wrap
Methods
getItemRepairCost
Returns the repair-cost data value on the first input item, or 0 if it has none. This value contributes to anvil level cost; it is not an item count.
Returns: the first input item's repair cost, 0 when it carries none
getLeftInput
Returns the first input item (slot 0), which is the item repaired or renamed.
Returns: the first input item
getLevelCost
Returns the current operation cost in experience levels. It can be nonzero with no result when the cost is at least 40; players with infinite materials may still take such a result. Rename-only costs are capped at 39.
Returns: the level cost the anvil is asking for, 0 when there is nothing to take
getMaximumLevelCost
Returns the fixed threshold of 40 used by anvil cost rules. Rename-only costs are capped at 39; other costs of 40 or more normally suppress the result.
Returns: 40
getName
getOutput
Returns the current client-side result in slot 2; taking it applies the rename and charges the anvil cost.
Returns: the result the anvil is currently offering
getRightInput
Returns the second input item (slot 1), used as repair material or an enchantment source. It may be empty, including when the anvil is used only for renaming.
Returns: the second input item
setName
Sets the anvil rename-box text. Changing the box updates the anvil's cost and result; the renamed item is obtained by taking the result. The box accepts at most 50 characters.
Parameters:
name: the text to put in the rename box
Returns: self for chaining.