Skip to content

AnvilInventory ​

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

Since1.8.4

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 ​

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

getLeftInput(): ItemStackHelperSince1.8.4#
Returns the first input item (slot 0), which is the item repaired or renamed.
Returns: the first input item

getLevelCost ​

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

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

getName(): StringSince1.8.4#
Returns the current text in the anvil rename box. This is box text, not a guarantee that the anvil will produce a result; it may remain readable after the first input is removed.
Returns: the current text of the anvil's rename box

getOutput ​

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

getRightInput(): ItemStackHelperSince1.8.4#
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 ​

setName(String name): AnvilInventorySince1.8.4#
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.

toString ​

toString(): String#
Returns this wrapper's fixed diagnostic label.
Returns: AnvilInventory:{}