Class MerchantRecipe

java.lang.Object
org.bukkit.inventory.MerchantRecipe
All Implemented Interfaces:
Recipe

public class MerchantRecipe extends Object implements Recipe
Represents a merchant's trade.

Trades can take one or two ingredients, and provide one result. The ingredients' ItemStack amounts are respected in the trade.

A trade has a maximum number of uses. A Villager may periodically replenish its trades by resetting the uses of its merchant recipes to 0, allowing them to be used again.

A trade may or may not reward experience for being completed.

During trades, the MerchantRecipe dynamically adjusts the amount of its first ingredient based on the following criteria:

  • Demand: This value is periodically updated by the villager that owns this merchant recipe based on how often the recipe has been used since it has been last restocked in relation to its maximum uses. The amount by which the demand influences the amount of the first ingredient is scaled by the recipe's price multiplier, and can never be below zero.
  • Special price: This value is dynamically updated whenever a player starts and stops trading with a villager that owns this merchant recipe. It is based on the player's individual reputation with the villager, and the player's currently active status effects (see PotionEffectType.HERO_OF_THE_VILLAGE). The influence of the player's reputation on the special price is scaled by the recipe's price multiplier.
The adjusted amount of the first ingredient is calculated by adding up the original amount of the first ingredient, the demand scaled by the recipe's price multiplier and truncated to the next lowest integer value greater than or equal to 0, and the special price, and then constraining the resulting value between 1 and the item stack's maximum stack size.