Record Class ShopItem

java.lang.Object
java.lang.Record
com.pixelmonmod.pixelmon.api.shop.ShopItem
Record Components:
uuid - The unique identifier of the shop item
itemStack - The item stack to be sold or bought
buyPrice - The price the player pays to buy the item
sellPrice - The price the player receives when selling the item

public record ShopItem(UUID uuid, net.minecraft.world.item.ItemStack itemStack, double buyPrice, double sellPrice) extends Record
Simple record that represents an item in an NPC's shop.
Contains the item stack, buy price, and sell price.
The buy price is the price the player pays to buy the item. If the buy price is less than, or equal to, 0 then the item is not purchasable. This can be checked using ShopItem#isPurchasable().
The sell price is the price the player receives when selling the item. If the sell price is less than, or equal to, 0 then the item is not sellable. This can be checked using ShopItem#isSellable(). It is best to use ShopItem#canSell(ItemStack) to check if the item can be sold to the shop as this method will check if the item stacks are the same and if the NBT data matches as well as the sell price.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final com.mojang.serialization.Codec<ShopItem>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    ShopItem(UUID uuid, net.minecraft.world.item.ItemStack itemStack, double buyPrice, double sellPrice)
    Creates an instance of a ShopItem record class.
    ShopItem(net.minecraft.world.item.ItemStack itemStack, double buyPrice, double sellPrice)
    Creates a new ShopItem with the given item stack, buy price, and sell price.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Returns the value of the buyPrice record component.
    boolean
    canSell(net.minecraft.world.item.ItemStack itemStack)
    Checks if the given item stack can be sold to the shop.
    static ShopItem
    decode(net.minecraft.network.FriendlyByteBuf buffer)
     
    void
    encode(net.minecraft.network.FriendlyByteBuf buffer)
     
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    boolean
    Checks if the item is purchasable.
    boolean
    Checks if the item is sellable.
    net.minecraft.world.item.ItemStack
    Returns the value of the itemStack record component.
    double
    Returns the value of the sellPrice record component.
    final String
    Returns a string representation of this record class.
    Returns the value of the uuid record component.
    withBuyPrice(double buyPrice)
    Creates a new ShopItem with the given buy price.
    withItemStack(net.minecraft.world.item.ItemStack itemStack)
    Creates a new ShopItem with the given item stack.
    withSellPrice(double sellPrice)
    Creates a new ShopItem with the given sell price.

    Methods inherited from class java.lang.Object

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

    • CODEC

      public static final com.mojang.serialization.Codec<ShopItem> CODEC
  • Constructor Details

    • ShopItem

      public ShopItem(net.minecraft.world.item.ItemStack itemStack, double buyPrice, double sellPrice)
      Creates a new ShopItem with the given item stack, buy price, and sell price.
      Parameters:
      itemStack - The item stack to be sold or bought
      buyPrice - The price the player pays to buy the item
      sellPrice - The price the player receives when selling the item
    • ShopItem

      public ShopItem(UUID uuid, net.minecraft.world.item.ItemStack itemStack, double buyPrice, double sellPrice)
      Creates an instance of a ShopItem record class.
      Parameters:
      uuid - the value for the uuid record component
      itemStack - the value for the itemStack record component
      buyPrice - the value for the buyPrice record component
      sellPrice - the value for the sellPrice record component
  • Method Details

    • canSell

      public boolean canSell(net.minecraft.world.item.ItemStack itemStack)
      Checks if the given item stack can be sold to the shop.
      This method will check if the item stacks are the same and if the NBT data matches as well as the sell price.
      Parameters:
      itemStack - The item stack to check
      Returns:
      True if the item can be sold
    • isPurchasable

      public boolean isPurchasable()
      Checks if the item is purchasable.
      If the buy price is less than, or equal to, 0 then the item is not purchasable.
      Returns:
      True if the item is purchasable
    • isSellable

      public boolean isSellable()
      Checks if the item is sellable.
      If the sell price is less than, or equal to, 0 then the item is not sellable.
      Returns:
      True if the item is sellable
    • withBuyPrice

      public ShopItem withBuyPrice(double buyPrice)
      Creates a new ShopItem with the given buy price.
      Parameters:
      buyPrice - The new buy price
      Returns:
      The new shop item
    • withSellPrice

      public ShopItem withSellPrice(double sellPrice)
      Creates a new ShopItem with the given sell price.
      Parameters:
      sellPrice - The new sell price
      Returns:
      The new shop item
    • withItemStack

      public ShopItem withItemStack(net.minecraft.world.item.ItemStack itemStack)
      Creates a new ShopItem with the given item stack.
      Parameters:
      itemStack - The new item stack
      Returns:
      The new shop item
    • encode

      public void encode(net.minecraft.network.FriendlyByteBuf buffer)
    • decode

      public static ShopItem decode(net.minecraft.network.FriendlyByteBuf buffer)
    • 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.
    • uuid

      public UUID uuid()
      Returns the value of the uuid record component.
      Returns:
      the value of the uuid record component
    • itemStack

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

      public double buyPrice()
      Returns the value of the buyPrice record component.
      Returns:
      the value of the buyPrice record component
    • sellPrice

      public double sellPrice()
      Returns the value of the sellPrice record component.
      Returns:
      the value of the sellPrice record component