Class ItemStack

java.lang.Object
com.hypixel.hytale.server.core.inventory.ItemStack
All Implemented Interfaces:
NetworkSerializable<ItemWithAllMetadata>

public class ItemStack extends Object implements NetworkSerializable<ItemWithAllMetadata>
Represents a quantified collection of an item. Useful for representing an item with a specific quantity or data.
  • Field Details

    • EMPTY_ARRAY

      @Nonnull public static final ItemStack[] EMPTY_ARRAY
      An empty ItemStack array to reduce allocation overhead.
    • CODEC

      @Nonnull public static final BuilderCodec<ItemStack> CODEC
      The codec used to parse ItemStack instances.
    • EMPTY

      @Nonnull public static final ItemStack EMPTY
      Represents an empty item stack that can be used where needed.
  • Constructor Details

    • ItemStack

      public ItemStack(@Nonnull String itemId, int quantity, @Nullable org.bson.BsonDocument metadata)
      Constructor for an ItemStack instance.
      Parameters:
      itemId - The block type key of the associated item.
      quantity - The quantity of this item stack.
      metadata - The additional metadata of this item stack.
    • ItemStack

      public ItemStack(@Nonnull String itemId, int quantity, double durability, double maxDurability, @Nullable org.bson.BsonDocument metadata)
      Constructor for an ItemStack instance.
      Parameters:
      itemId - The block type key of the associated item.
      quantity - The quantity of the item stack.
      durability - The current durability of this item stack.
      maxDurability - The maximum durability of this item stack.
      metadata - The additional metadata of this item stack.
    • ItemStack

      public ItemStack(@Nonnull String itemId, int quantity, double durability, double maxDurability, int qualityIndexOverride, @Nullable org.bson.BsonDocument metadata)
      Constructor for an ItemStack instance.
      Parameters:
      itemId - The block type key of the associated item.
      quantity - The quantity of the item stack.
      durability - The current durability of this item stack.
      maxDurability - The maximum durability of this item stack.
      qualityIndexOverride - The quality index of this item stack, overriding the item's configured quality.
      metadata - The additional metadata of this item stack.
    • ItemStack

      public ItemStack(@Nonnull String itemId)
      Constructor for an ItemStack instance.
      Parameters:
      itemId - The block type key of the associated item.
    • ItemStack

      public ItemStack(@Nonnull String itemId, int quantity)
      Constructor for an ItemStack instance.
      Parameters:
      itemId - The block type key of the associated item.
      quantity - The quantity of this item stack.
  • Method Details

    • getItemId

      @Nonnull public String getItemId()
      Returns:
      the block type key of the item associate with this item stack.
    • getQuantity

      public int getQuantity()
      Returns:
      the quantity of this item stack.
    • getMetadata

      @Nullable @Deprecated public org.bson.BsonDocument getMetadata()
      Deprecated.
      Returns:
      the metadata of this item stack.
    • isUnbreakable

      public boolean isUnbreakable()
      Determines whether this item stack is unbreakable.
      Returns:
      true if the item stack is unbreakable, false otherwise.
    • isBroken

      public boolean isBroken()
      Determines whether this item stack is broken.
      Returns:
      true if the item stack is broken, false otherwise.
    • getMaxDurability

      public double getMaxDurability()
      Returns:
      the maximum durability of this item stack.
    • getDurability

      public double getDurability()
      Returns:
      the durability of this item stack.
    • getQualityIndex

      public int getQualityIndex()
      Returns:
      the quality index of this item stack.
    • isEmpty

      public boolean isEmpty()
      Determines whether this item stack is considered empty.
      Returns:
      true if the item stack is empty, false otherwise.
    • getOverrideDroppedItemAnimation

      public boolean getOverrideDroppedItemAnimation()
      Determines whether to override the dropped item animation for this item stack.
      Returns:
      true if it should override, false otherwise.
    • setOverrideDroppedItemAnimation

      public void setOverrideDroppedItemAnimation(boolean b)
      Called to set whether to override the dropped item animation for this item stack.
      Parameters:
      b - Whether to override it.
    • getBlockKey

      @Nullable public String getBlockKey()
      Called to fetch the block key of the item associated with this item stack.
      Returns:
      the block key, or null if the item does not have a block ID.
    • getItem

      @Nonnull public Item getItem()
      Returns:
      the Item associated with this item stack.
    • isValid

      public boolean isValid()
      Determines whether this item stack is considered valid.
      Returns:
      true if the item stack is valid, false otherwise.
    • withDurability

      @Nonnull public ItemStack withDurability(double durability)
      Called to fetch a copy of this item stack, reconfigured with the provided durability.
      Parameters:
      durability - The durability to assign to the copy of the items stack.
      Returns:
      the copy of the item stack with the configured durability.
    • withMaxDurability

      @Nonnull public ItemStack withMaxDurability(double maxDurability)
      Called to fetch a copy of this item stack, reconfigured with the provided max durability.
      Parameters:
      maxDurability - The max durability to assign to the copy of the items stack.
      Returns:
      the copy of the item stack with the configured max durability.
    • withQuality

      @Nonnull public ItemStack withQuality(int quality)
      Called to fetch a copy of this item stack, reconfigured with the provided quality index.
      Parameters:
      quality - The quality index to assign to the copy of the item stack.
      Returns:
      the copy of the item stack with the configured quality.
    • withIncreasedDurability

      @Nonnull public ItemStack withIncreasedDurability(double inc)
      Called to fetch a copy of this item stack, increasing its durability with the provided amount.
      Parameters:
      inc - The provided amount to increase the durability by.
      Returns:
      the copy of the item stack with the increased durability.
    • withRestoredDurability

      @Nonnull public ItemStack withRestoredDurability(double maxDurability)
      Called to fetch a copy of this item stack, increasing its max durability with the provided amount.
      Parameters:
      maxDurability - The provided amount to increase the max durability by.
      Returns:
      the copy of the item stack with the increased max durability.
    • withState

      @Nonnull public ItemStack withState(@Nonnull String state)
      Called to fetch a copy of this item stack, reconfigured with the new item from the provided state.
      Parameters:
      state - The provided state to read the new item from.
      Returns:
      the copy of the item stack with the reconfigured item from the state.
    • withQuantity

      @Nullable public ItemStack withQuantity(int quantity)
      Called to fetch a copy of this item stack, reconfigured with the new quantity.
      Parameters:
      quantity - The provided quantity to set on the item stack copy.
      Returns:
      the copy of the item stack with the reconfigured quantity.
    • cleanCopy

      @Nonnull public ItemStack cleanCopy()
      Called to fetch a copy of this item stack without transient runtime flags.
      Returns:
      the clean copy of this item stack.
    • withMetadata

      @Nonnull public ItemStack withMetadata(@Nullable org.bson.BsonDocument metadata)
      Called to fetch a copy of this item stack, reconfigured with the given metadata.
      Parameters:
      metadata - The given metadata to set on the new item stack copy.
      Returns:
      the copy of the item stack with the reconfigured metadata.
    • withMetadata

      @Nonnull public <T> ItemStack withMetadata(@Nonnull KeyedCodec<T> keyedCodec, @Nullable T data)
    • withMetadata

      @Nonnull public <T> ItemStack withMetadata(@Nonnull String key, @Nonnull Codec<T> codec, @Nullable T data)
    • withMetadata

      @Nonnull public ItemStack withMetadata(@Nonnull String key, @Nullable org.bson.BsonValue bsonValue)
    • toPacket

      public ItemWithAllMetadata toPacket()
      Specified by:
      toPacket in interface NetworkSerializable<ItemWithAllMetadata>
    • isStackableWith

      public boolean isStackableWith(@Nullable ItemStack itemStack)
      Compares if the two ItemStack's are allowed to be stacked together. Note: Does not check if the item quantity can be combined.
      Parameters:
      itemStack - The item stack to compare to
      Returns:
      If the two types are allowed to be stacked
    • isEquivalentType

      public boolean isEquivalentType(@Nullable ItemStack itemStack)
      Compares if the two ItemStack's are of the same 'type'
      Parameters:
      itemStack - The item stack to compare to
      Returns:
      If the two types are of equivalent type
    • getFromMetadataOrNull

      @Nullable public <T> T getFromMetadataOrNull(@Nonnull KeyedCodec<T> keyedCodec)
    • getFromMetadataOrNull

      @Nullable public <T> T getFromMetadataOrNull(@Nonnull String key, @Nonnull Codec<T> codec)
    • getFromMetadataOrDefault

      public <T> T getFromMetadataOrDefault(@Nonnull String key, @Nonnull BuilderCodec<T> codec)
    • getDisplayName

      @Nonnull public Message getDisplayName()
      Returns:
      the ItemDisplayMetadata name override if set, otherwise the item asset's translation message.
    • getDisplayDescription

      @Nonnull public Message getDisplayDescription()
      Returns:
      the ItemDisplayMetadata description override if set, otherwise the item asset's description translation message.
    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      @Nonnull public String toString()
      Overrides:
      toString in class Object
    • isEmpty

      public static boolean isEmpty(@Nullable ItemStack itemFrom)
    • isStackableWith

      public static boolean isStackableWith(@Nullable ItemStack a, @Nullable ItemStack b)
    • isEquivalentType

      public static boolean isEquivalentType(@Nullable ItemStack a, ItemStack b)
    • isSameItemType

      public static boolean isSameItemType(@Nullable ItemStack a, @Nullable ItemStack b)