Record Class ShopItem
java.lang.Object
java.lang.Record
com.pixelmonmod.pixelmon.api.shop.ShopItem
- Record Components:
uuid- The unique identifier of the shop itemitemStack- The item stack to be sold or boughtbuyPrice- The price the player pays to buy the itemsellPrice- 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
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
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 -
Constructor Summary
ConstructorsConstructorDescriptionShopItem(UUID uuid, net.minecraft.world.item.ItemStack itemStack, double buyPrice, double sellPrice) Creates an instance of aShopItemrecord class.ShopItem(net.minecraft.world.item.ItemStack itemStack, double buyPrice, double sellPrice) Creates a newShopItemwith the given item stack, buy price, and sell price. -
Method Summary
Modifier and TypeMethodDescriptiondoublebuyPrice()Returns the value of thebuyPricerecord component.booleancanSell(net.minecraft.world.item.ItemStack itemStack) Checks if the given item stack can be sold to the shop.static ShopItemdecode(net.minecraft.network.FriendlyByteBuf buffer) voidencode(net.minecraft.network.FriendlyByteBuf buffer) final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanChecks if the item is purchasable.booleanChecks if the item is sellable.net.minecraft.world.item.ItemStackReturns the value of theitemStackrecord component.doubleReturns the value of thesellPricerecord component.final StringtoString()Returns a string representation of this record class.uuid()Returns the value of theuuidrecord component.withBuyPrice(double buyPrice) Creates a newShopItemwith the given buy price.withItemStack(net.minecraft.world.item.ItemStack itemStack) Creates a newShopItemwith the given item stack.withSellPrice(double sellPrice) Creates a newShopItemwith the given sell price.
-
Field Details
-
CODEC
-
-
Constructor Details
-
ShopItem
public ShopItem(net.minecraft.world.item.ItemStack itemStack, double buyPrice, double sellPrice) Creates a newShopItemwith the given item stack, buy price, and sell price.- Parameters:
itemStack- The item stack to be sold or boughtbuyPrice- The price the player pays to buy the itemsellPrice- 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 aShopItemrecord class.
-
-
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
Creates a newShopItemwith the given buy price.- Parameters:
buyPrice- The new buy price- Returns:
- The new shop item
-
withSellPrice
Creates a newShopItemwith the given sell price.- Parameters:
sellPrice- The new sell price- Returns:
- The new shop item
-
withItemStack
Creates a newShopItemwith 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
-
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
uuid
Returns the value of theuuidrecord component.- Returns:
- the value of the
uuidrecord component
-
itemStack
public net.minecraft.world.item.ItemStack itemStack()Returns the value of theitemStackrecord component.- Returns:
- the value of the
itemStackrecord component
-
buyPrice
public double buyPrice()Returns the value of thebuyPricerecord component.- Returns:
- the value of the
buyPricerecord component
-
sellPrice
public double sellPrice()Returns the value of thesellPricerecord component.- Returns:
- the value of the
sellPricerecord component
-