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
-
Constructor Summary
ConstructorDescriptionShopItem
(UUID uuid, net.minecraft.world.item.ItemStack itemStack, double buyPrice, double sellPrice) Creates an instance of aShopItem
record class.ShopItem
(net.minecraft.world.item.ItemStack itemStack, double buyPrice, double sellPrice) Creates a newShopItem
with the given item stack, buy price, and sell price. -
Method Summary
Modifier and TypeMethodDescriptiondouble
buyPrice()
Returns the value of thebuyPrice
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
hashCode()
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 theitemStack
record component.double
Returns the value of thesellPrice
record component.final String
toString()
Returns a string representation of this record class.uuid()
Returns the value of theuuid
record component.withBuyPrice
(double buyPrice) Creates a newShopItem
with the given buy price.withItemStack
(net.minecraft.world.item.ItemStack itemStack) Creates a newShopItem
with the given item stack.withSellPrice
(double sellPrice) Creates a newShopItem
with the given sell price.
-
Field Details
-
CODEC
-
-
Constructor Details
-
ShopItem
public ShopItem(net.minecraft.world.item.ItemStack itemStack, double buyPrice, double sellPrice) Creates a newShopItem
with 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 aShopItem
record 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 newShopItem
with the given buy price.- Parameters:
buyPrice
- The new buy price- Returns:
- The new shop item
-
withSellPrice
Creates a newShopItem
with the given sell price.- Parameters:
sellPrice
- The new sell price- Returns:
- The new shop item
-
withItemStack
Creates a newShopItem
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
-
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 theuuid
record component.- Returns:
- the value of the
uuid
record component
-
itemStack
public net.minecraft.world.item.ItemStack itemStack()Returns the value of theitemStack
record component.- Returns:
- the value of the
itemStack
record component
-
buyPrice
public double buyPrice()Returns the value of thebuyPrice
record component.- Returns:
- the value of the
buyPrice
record component
-
sellPrice
public double sellPrice()Returns the value of thesellPrice
record component.- Returns:
- the value of the
sellPrice
record component
-