Skip to content

VillagerInventory ​

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

Since1.3.1

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 ​

canRefreshTrades(): booleanSince1.3.1#
Returns the menu's restock flag.
Returns: true if a restock is available, false otherwise

getExperience ​

getExperience(): intSince1.3.1#
Returns the trader's current experience value from the menu.
Returns: the trader's current experience

getLevelProgress ​

getLevelProgress(): intSince1.3.1#
Returns the trader level stored in the menu.
Returns: the trader's level

getMerchantRewardedExperience ​

getMerchantRewardedExperience(): intSince1.3.1#
Returns the experience value calculated for the current trade inputs.
Returns: the calculated future experience value

getTrades ​

getTrades(): List<TradeOfferHelper>Since1.3.1#
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 ​

isLeveled(): booleanSince1.3.1#
Returns whether the menu displays a progress bar.
Returns: true if the level bar is being shown, false otherwise

selectTrade ​

selectTrade(int index): VillagerInventorySince1.3.1#
Selects a trade by its zero-based position in getTrades().

Parameters:

Returns: this inventory for chaining

toString ​

toString(): String#
Returns a diagnostic label containing the value from getLevelProgress().
Returns: VillagerInventory:{"level": level}, with level replaced by the value returned by getLevelProgress()