Class StackingRule

java.lang.Object
net.minestom.server.item.StackingRule
Direct Known Subclasses:
VanillaStackingRule

public abstract class StackingRule
extends java.lang.Object
Represents the stacking rule of an ItemStack. This can be used to mimic the vanilla one (using the displayed item quantity) or a complete new one which can be stored in lore, name, etc...
  • Constructor Summary

    Constructors 
    Constructor Description
    StackingRule​(int maxSize)  
  • Method Summary

    Modifier and Type Method Description
    abstract ItemStack apply​(ItemStack item, int newAmount)
    Changes the size of the ItemStack to newAmount.
    abstract boolean canApply​(ItemStack item, int newAmount)
    Used to know if an ItemStack can have the size newAmount applied.
    abstract boolean canBeStacked​(ItemStack item1, ItemStack item2)
    Used to know if two ItemStack can be stacked together.
    abstract int getAmount​(ItemStack itemStack)
    Used to determine the current stack size of an ItemStack.
    int getMaxSize()
    Gets the max size of a stack.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • canBeStacked

      public abstract boolean canBeStacked​(@NotNull ItemStack item1, @NotNull ItemStack item2)
      Used to know if two ItemStack can be stacked together.
      Parameters:
      item1 - the first ItemStack
      item2 - the second ItemStack
      Returns:
      true if both ItemStack can be stacked together (without taking their amount in consideration)
    • canApply

      public abstract boolean canApply​(@NotNull ItemStack item, int newAmount)
      Used to know if an ItemStack can have the size newAmount applied.
      Parameters:
      item - the ItemStack to check
      newAmount - the desired new amount
      Returns:
      true if item can have its stack size set to newAmount
    • apply

      @NotNull public abstract ItemStack apply​(@NotNull ItemStack item, int newAmount)
      Changes the size of the ItemStack to newAmount. At this point we know that the item can have this stack size applied.
      Parameters:
      item - the ItemStack to applies the size to
      newAmount - the new item size
      Returns:
      the new ItemStack with the new amount
    • getAmount

      public abstract int getAmount​(@NotNull ItemStack itemStack)
      Used to determine the current stack size of an ItemStack. It is possible to have it stored in its Data object, lore, etc...
      Parameters:
      itemStack - the ItemStack to check the size
      Returns:
      the correct size of ItemStack
    • getMaxSize

      public int getMaxSize()
      Gets the max size of a stack.
      Returns:
      the max size of a stack