Class 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 limited number of uses, after which the trade can no longer be used, unless the player uses a different trade, which will cause its maximum uses to increase.
    A trade may or may not reward experience for being completed.
    See Also:
    VillagerReplenishTradeEvent
    • Constructor Detail

      • MerchantRecipe

        public MerchantRecipe​(ItemStack result,
                              int maxUses)
      • MerchantRecipe

        public MerchantRecipe​(ItemStack result,
                              int uses,
                              int maxUses,
                              boolean experienceReward)
    • Method Detail

      • getResult

        public ItemStack getResult()
        Description copied from interface: Recipe
        Get the result of this recipe.
        Specified by:
        getResult in interface Recipe
        Returns:
        The result stack
      • addIngredient

        public void addIngredient​(ItemStack item)
      • removeIngredient

        public void removeIngredient​(int index)
      • setIngredients

        public void setIngredients​(List<ItemStack> ingredients)
      • 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.
        The maximum uses of this trade may increase when a player trades with the owning merchant.
        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 for the trade.
        Returns:
        whether to reward experience for completing this trade
      • setExperienceReward

        public void setExperienceReward​(boolean flag)
        Set whether to reward experience for the trade.
        Parameters:
        flag - whether to reward experience for completing this trade