Package org.bukkit.inventory
Class MerchantRecipe
java.lang.Object
org.bukkit.inventory.MerchantRecipe
- All Implemented Interfaces:
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 itsmaximum uses
. The amount by which the demand influences the amount of the first ingredient is scaled by the recipe'sprice 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 (seePotionEffectType.HERO_OF_THE_VILLAGE
). The influence of the player's reputation on the special price is scaled by the recipe'sprice multiplier
.
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
.-
Constructor Summary
ConstructorDescriptionMerchantRecipe
(ItemStack result, int maxUses) MerchantRecipe
(ItemStack result, int uses, int maxUses, boolean experienceReward) MerchantRecipe
(ItemStack result, int uses, int maxUses, boolean experienceReward, int villagerExperience, float priceMultiplier) MerchantRecipe
(ItemStack result, int uses, int maxUses, boolean experienceReward, int villagerExperience, float priceMultiplier, int demand, int specialPrice) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addIngredient
(ItemStack item) void
Modifies the amount of the givenItemStack
in the same way as MerchantRecipe dynamically adjusts the amount of the first ingredient during trading.Gets theadjusted
first ingredient.int
Get the demand for this trade.int
Get the maximum number of uses this trade has.float
Gets the price multiplier for the cost of this trade.Get the result of this recipe.int
Get the special price for this trade.int
getUses()
Get the number of times this trade has been used.int
Gets the amount of experience the villager earns from this trade.boolean
Whether to reward experience to the player for the trade.void
removeIngredient
(int index) void
setDemand
(int demand) Set the demand for this trade.void
setExperienceReward
(boolean flag) Set whether to reward experience to the player for the trade.void
setIngredients
(List<ItemStack> ingredients) void
setMaxUses
(int maxUses) Set the maximum number of uses this trade has.void
setPriceMultiplier
(float priceMultiplier) Sets the price multiplier for the cost of this trade.void
setSpecialPrice
(int specialPrice) Set the special price for this trade.void
setUses
(int uses) Set the number of times this trade has been used.void
setVillagerExperience
(int villagerExperience) Sets the amount of experience the villager earns from this trade.
-
Constructor Details
-
MerchantRecipe
-
MerchantRecipe
-
MerchantRecipe
-
MerchantRecipe
-
-
Method Details
-
getResult
Description copied from interface:Recipe
Get the result of this recipe. -
addIngredient
-
removeIngredient
public void removeIngredient(int index) -
setIngredients
-
getIngredients
-
getAdjustedIngredient1
Gets theadjusted
first ingredient.- Returns:
- the adjusted first ingredient, or
null
if this recipe has no ingredients - See Also:
-
adjust
Modifies the amount of the givenItemStack
in the same way as MerchantRecipe dynamically adjusts the amount of the first ingredient during trading.
This is calculated by adding up the original amount of the item, the demand scaled by the recipe'sprice 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 between1
and theItemStack
'smaximum stack size
.- Parameters:
itemStack
- the item to adjust
-
getDemand
public int getDemand()Get the demand for this trade.- Returns:
- the demand
-
setDemand
public void setDemand(int demand) Set the demand for this trade.- Parameters:
demand
- the new demand
-
getSpecialPrice
public int getSpecialPrice()Get the special price for this trade.- Returns:
- special price value
-
setSpecialPrice
public void setSpecialPrice(int specialPrice) Set the special price for this trade.- Parameters:
specialPrice
- special price value
-
getUses
public int getUses()Get the number of times this trade has been used.- Returns:
- the number of uses
-
setUses
public void setUses(int uses) Set the number of times this trade has been used.- Parameters:
uses
- the number of uses
-
getMaxUses
public int getMaxUses()Get the maximum number of uses this trade has.- Returns:
- the maximum number of uses
-
setMaxUses
public void setMaxUses(int maxUses) Set the maximum number of uses this trade has.- Parameters:
maxUses
- the maximum number of time this trade can be used
-
hasExperienceReward
public boolean hasExperienceReward()Whether to reward experience to the player for the trade.- Returns:
- whether to reward experience to the player for completing this trade
-
setExperienceReward
public void setExperienceReward(boolean flag) Set whether to reward experience to the player for the trade.- Parameters:
flag
- whether to reward experience to the player for completing this trade
-
getVillagerExperience
public int getVillagerExperience()Gets the amount of experience the villager earns from this trade.- Returns:
- villager experience
-
setVillagerExperience
public void setVillagerExperience(int villagerExperience) Sets the amount of experience the villager earns from this trade.- Parameters:
villagerExperience
- new experience amount
-
getPriceMultiplier
public float getPriceMultiplier()Gets the price multiplier for the cost of this trade.- Returns:
- price multiplier
-
setPriceMultiplier
public void setPriceMultiplier(float priceMultiplier) Sets the price multiplier for the cost of this trade.- Parameters:
priceMultiplier
- new price multiplier
-