EnchantInventory
com.jsmacrosce.jsmacros.client.api.classes.inventory.EnchantInventory
Handles an open enchanting table screen. Its three options use indices 0–2 in the option getters and doEnchant(int); getRequiredLevels() reports costs,
getEnchantmentIds() and getEnchantmentLevels() report clue details, and getEnchantments() and getEnchantmentHelpers() provide resolved names or wrappers. The item and lapis slots are 0 and 1, respectively.
js
const inv = Player.openInventory();
if (inv instanceof Inventories.Enchant) {
if (!inv.getItemToEnchant().isEmpty()) {
const enchants = inv.getEnchantmentHelpers();
for (let i = 0; enchants.length > i; i++) {
if (enchants[i] === null) continue;
Chat.log(`${i}: ${enchants[i].getId()} ${enchants[i].getLevel()} for ${inv.getRequiredLevels()[i]} levels`);
}
}
}Available in scripts as Inventories.Enchant.
Methods
doEnchant
Requests the menu to select an option at index 0–2. The local check refuses an invalid index, a missing item, or an unavailable option; ordinary players also need at least
index + 1 lapis and experience levels at least both that amount and the threshold from getRequiredLevels(). On successful ordinary-player handling, that amount of lapis and levels is consumed; players with infinite materials bypass sufficiency checks and lapis consumption. true means the local check passed and the request was sent, not that the server confirmed the enchantment; false means the local check refused it.Parameters:
index: which of the three options to buy, 0 to 2
Returns:
true if the local menu check passes and the request is sent; false if the check refuses itgetEnchantmentHelpers
Returns wrappers for the three option clues; each wrapper's level is the offered level, and unresolved clues are
null.Returns: the three options as enchantment wrappers, in order, with
null for unresolved cluesgetEnchantmentIds
getEnchantmentLevels
Returns the menu's three offered enchantment levels, indexed 0–2. An unavailable option is represented by
-1; this is the menu's live array.Returns: the level of each option, in order, -1 for an option the table is not offering
getEnchantments
Returns the three option names as full-level display text; unresolved clues are
null. Entries retain the option indices 0–2.Returns: the three options as text, in order, with
null for unresolved cluesgetItemToEnchant
Returns the stack in the enchanting menu's item slot (slot 0).
Returns: the item being enchanted
getLapis
Returns the lapis stack in slot 1. A successful ordinary-player enchant consumes
index + 1 lapis for the selected option; players with infinite materials do not consume lapis.Returns: the lapis lazuli stack in slot 1
getRequiredLevels
Returns the menu's three required-level thresholds, indexed 0–2. A zero marks an option the menu is not offering. This is the menu's live array; on a successful ordinary-player enchant, the menu deducts the option index plus one levels, not this threshold. Players with infinite materials bypass the level-sufficiency check.
Returns: the required-level threshold of each option, in order, 0 for an option the table is not offering