# 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()](#com.jsmacrosce.jsmacros.client.api.helper.world.entity.MerchantEntityHelper_getTrades-) and [refreshTrades()](#com.jsmacrosce.jsmacros.client.api.helper.world.entity.MerchantEntityHelper_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()](#com.jsmacrosce.jsmacros.client.api.helper.world.entity.MerchantEntityHelper_getExperience-). [hasCustomer()](#com.jsmacrosce.jsmacros.client.api.helper.world.entity.MerchantEntityHelper_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 {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.MerchantEntityHelper_constructor-T-}

```js
new MerchantEntityHelper(T extends AbstractVillager e)
```

Wraps the supplied merchant entity, retaining the same reference.

**Parameters:**
- `e`: merchant entity to wrap

## Methods

### getExperience {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.MerchantEntityHelper_getExperience-}

```js
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 {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.MerchantEntityHelper_getTrades-}

```js
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 {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.MerchantEntityHelper_hasCustomer-}

```js
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 {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.MerchantEntityHelper_refreshTrades-}

```js
refreshTrades(): List<TradeOfferHelper>
```

Clears the cached offers and returns the regenerated list. On the client, the
 cache is cleared before [getTrades()](#com.jsmacrosce.jsmacros.client.api.helper.world.entity.MerchantEntityHelper_getTrades-) throws.

**Returns:** the merchant's regenerated offers
