public class MerchantRecipe extends Object implements Recipe
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
.
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 and Description |
---|
MerchantRecipe(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) |
Modifier and Type | Method and Description |
---|---|
void |
addIngredient(ItemStack item) |
void |
adjust(ItemStack itemStack)
Modifies the amount of the given
ItemStack in the same way as
MerchantRecipe dynamically adjusts the amount of the first ingredient
during trading. |
ItemStack |
getAdjustedIngredient1()
Gets the
adjusted first ingredient. |
int |
getDemand()
Get the demand for this trade.
|
List<ItemStack> |
getIngredients() |
int |
getMaxUses()
Get the maximum number of uses this trade has.
|
float |
getPriceMultiplier()
Gets the price multiplier for the cost of this trade.
|
ItemStack |
getResult()
Get the result of this recipe.
|
int |
getSpecialPrice()
Get the special price for this trade.
|
int |
getUses()
Get the number of times this trade has been used.
|
int |
getVillagerExperience()
Gets the amount of experience the villager earns from this trade.
|
boolean |
hasExperienceReward()
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.
|
public MerchantRecipe(@NotNull ItemStack result, int maxUses)
public MerchantRecipe(@NotNull ItemStack result, int uses, int maxUses, boolean experienceReward)
public MerchantRecipe(@NotNull ItemStack result, int uses, int maxUses, boolean experienceReward, int villagerExperience, float priceMultiplier)
public MerchantRecipe(@NotNull ItemStack result, int uses, int maxUses, boolean experienceReward, int villagerExperience, float priceMultiplier, int demand, int specialPrice)
@NotNull public ItemStack getResult()
Recipe
public void addIngredient(@NotNull ItemStack item)
public void removeIngredient(int index)
@Nullable public ItemStack getAdjustedIngredient1()
adjusted
first ingredient.null
if this
recipe has no ingredientsadjust(ItemStack)
public void adjust(@Nullable ItemStack itemStack)
ItemStack
in the same way as
MerchantRecipe dynamically adjusts the amount of the first ingredient
during trading.
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
ItemStack
's maximum stack size
.itemStack
- the item to adjustpublic int getDemand()
public void setDemand(int demand)
demand
- the new demandpublic int getSpecialPrice()
public void setSpecialPrice(int specialPrice)
specialPrice
- special price valuepublic int getUses()
public void setUses(int uses)
uses
- the number of usespublic int getMaxUses()
public void setMaxUses(int maxUses)
maxUses
- the maximum number of time this trade can be usedpublic boolean hasExperienceReward()
public void setExperienceReward(boolean flag)
flag
- whether to reward experience to the player for completing
this tradepublic int getVillagerExperience()
public void setVillagerExperience(int villagerExperience)
villagerExperience
- new experience amountpublic float getPriceMultiplier()
public void setPriceMultiplier(float priceMultiplier)
priceMultiplier
- new price multiplierCopyright © 2022. All rights reserved.