VillagerInventory
com.jsmacrosce.jsmacros.client.api.classes.inventory.VillagerInventory
Handles an open villager trading screen. Use getTrades() to inspect its offers and selectTrade(int) to select one.
js
const inv = Player.openInventory();
if (inv instanceof Inventories.Villager) {
Chat.log(`level ${inv.getLevelProgress()}, ${inv.getExperience()} xp so far`);
const trades = inv.getTrades();
for (let i = 0; trades.size() > i; i++) {
Chat.log(`${i}: ${trades.get(i).getOutput().getItemId()}`);
}
}Available in scripts as Inventories.Villager.
Methods
canRefreshTrades
Returns the menu's restock flag.
Returns:
true if a restock is available, false otherwisegetExperience
Returns the trader's current experience value from the menu.
Returns: the trader's current experience
getLevelProgress
Returns the trader level stored in the menu.
Returns: the trader's level
getMerchantRewardedExperience
Returns the experience value calculated for the current trade inputs.
Returns: the calculated future experience value
getTrades
Returns helpers for the current menu offers in offer order. Each helper's index matches the position accepted by selectTrade(int).
Returns: list of trade offers
isLeveled
Returns whether the menu displays a progress bar.
Returns:
true if the level bar is being shown, false otherwiseselectTrade
Selects a trade by its zero-based position in getTrades().
Parameters:
index: the position in getTrades(), counting from 0
Returns: this inventory for chaining
toString
Returns a diagnostic label containing the value from getLevelProgress().
Returns:
VillagerInventory:{"level": level}, with level replaced by the value returned by getLevelProgress()