Skip to content

MerchantEntityHelper ​

com.jsmacrosce.jsmacros.client.api.helper.world.entity.MerchantEntityHelper

Helpers for villagers and wandering traders, which share the game's merchant base class.
Use EntityHelpers.Merchant to match either kind, or EntityHelpers.Villager for villagers alone.

getTrades() and refreshTrades() throw IllegalStateException on the client: the underlying merchant offer getter is server-only.

Read displayed offers from the open trading screen's VillagerInventory and trading experience through getExperience(). hasCustomer() reports the entity's local trading-player field, which is not a reliable indication of remote occupancy on a client.

js
// the trade list has to come from the open screen, not from the entity
const inv = Inventories.Inventory.create(Hud.getOpenScreen());  
if (inv !== null) {
 if (inv instanceof Inventories.Villager) {
   for (const trade of inv.getTrades()) {
     Chat.log(`#${trade.getIndex()}: ${trade.getOutput().getName()} `
       + `for ${trade.getLeftInput().getName()}`);  
   }
 }
}

Available in scripts as EntityHelpers.Merchant.

Type Parameters ​

  • T: the merchant entity type wrapped by this helper

Constructors ​

new MerchantEntityHelper ​

new MerchantEntityHelper(T extends AbstractVillager e)#
Wraps the supplied merchant entity, retaining the same reference.

Parameters:

  • e: merchant entity to wrap

Methods ​

getExperience ​

getExperience(): int#
Returns the merchant's accumulated trading experience; the base merchant implementation returns zero. For a villager, its level is available from VillagerEntityHelper.
Returns: the experience the merchant has banked

getTrades ​

getTrades(): List<TradeOfferHelper>#
Returns this merchant's offers. The underlying offer getter throws IllegalStateException on the client; read displayed offers from the open trading screen's VillagerInventory instead.
Returns: the merchant's offers

hasCustomer ​

hasCustomer(): boolean#
Returns whether this entity's local trading-player field is set. On a client this field is not a reliable indication that a remote player is trading with the merchant.
Returns: whether the local entity has a trading player

refreshTrades ​

refreshTrades(): List<TradeOfferHelper>#
Clears the cached offers and returns the regenerated list. On the client, the cache is cleared before getTrades() throws.
Returns: the merchant's regenerated offers