Record Class SimpleTrade

java.lang.Object
java.lang.Record
dev.architectury.registry.level.entity.trade.SimpleTrade
All Implemented Interfaces:
net.minecraft.world.entity.npc.VillagerTrades.ItemListing

public record SimpleTrade(net.minecraft.world.item.ItemStack primaryPrice, net.minecraft.world.item.ItemStack secondaryPrice, net.minecraft.world.item.ItemStack sale, int maxTrades, int experiencePoints, float priceMultiplier) extends Record implements net.minecraft.world.entity.npc.VillagerTrades.ItemListing
This class is the easiest implementation of a trade object. All trades added by vanilla do have custom classes like VillagerTrades.EmeraldForItems, but they aren't accessible.

Instead of widening the access of those classes or recreating them, this class was added to serve a basic trading implementation. To register a trade, just call TradeRegistry.registerVillagerTrade(net.minecraft.world.entity.npc.VillagerProfession, int, VillagerTrades.ItemListing...) or TradeRegistry.registerTradeForWanderingTrader(boolean, VillagerTrades.ItemListing...).

  • Constructor Summary

    Constructors
    Constructor
    Description
    SimpleTrade(net.minecraft.world.item.ItemStack primaryPrice, net.minecraft.world.item.ItemStack secondaryPrice, net.minecraft.world.item.ItemStack sale, int maxTrades, int experiencePoints, float priceMultiplier)
    Constructor for creating the trade.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    int
    Returns the value of the experiencePoints record component.
    @Nullable net.minecraft.world.item.trading.MerchantOffer
    getOffer(net.minecraft.world.entity.Entity entity, net.minecraft.util.RandomSource random)
     
    final int
    Returns a hash code value for this object.
    int
    Returns the value of the maxTrades record component.
    float
    Returns the value of the priceMultiplier record component.
    net.minecraft.world.item.ItemStack
    Returns the value of the primaryPrice record component.
    net.minecraft.world.item.ItemStack
    Returns the value of the sale record component.
    net.minecraft.world.item.ItemStack
    Returns the value of the secondaryPrice record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • SimpleTrade

      public SimpleTrade(net.minecraft.world.item.ItemStack primaryPrice, net.minecraft.world.item.ItemStack secondaryPrice, net.minecraft.world.item.ItemStack sale, int maxTrades, int experiencePoints, float priceMultiplier)
      Constructor for creating the trade. You can take a look at all the values the vanilla game uses right here VillagerTrades.TRADES.
      Parameters:
      primaryPrice - The first price a player has to pay to get the 'sale' stack.
      secondaryPrice - A optional, secondary price to pay as well as the primary one. If not needed just use ItemStack.EMPTY.
      sale - The ItemStack which a player can purchase in exchange for the two prices.
      maxTrades - The amount of trades one villager or wanderer can do. When the amount is surpassed, the trade can't be purchased anymore.
      experiencePoints - How much experience points does the player get, when trading. Vanilla uses between 2 and 30 for this.
      priceMultiplier - How much should the price rise, after the trade is used. It is added to the stack size of the primary price. Vanilla uses between 0.05 and 0.2.
  • Method Details

    • getOffer

      @Nullable public @Nullable net.minecraft.world.item.trading.MerchantOffer getOffer(net.minecraft.world.entity.Entity entity, net.minecraft.util.RandomSource random)
      Specified by:
      getOffer in interface net.minecraft.world.entity.npc.VillagerTrades.ItemListing
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • primaryPrice

      public net.minecraft.world.item.ItemStack primaryPrice()
      Returns the value of the primaryPrice record component.
      Returns:
      the value of the primaryPrice record component
    • secondaryPrice

      public net.minecraft.world.item.ItemStack secondaryPrice()
      Returns the value of the secondaryPrice record component.
      Returns:
      the value of the secondaryPrice record component
    • sale

      public net.minecraft.world.item.ItemStack sale()
      Returns the value of the sale record component.
      Returns:
      the value of the sale record component
    • maxTrades

      public int maxTrades()
      Returns the value of the maxTrades record component.
      Returns:
      the value of the maxTrades record component
    • experiencePoints

      public int experiencePoints()
      Returns the value of the experiencePoints record component.
      Returns:
      the value of the experiencePoints record component
    • priceMultiplier

      public float priceMultiplier()
      Returns the value of the priceMultiplier record component.
      Returns:
      the value of the priceMultiplier record component