Class StackableItem

All Implemented Interfaces:
EquipListener, TurnListener, UseListener, Stackable<StackableItem>, Killer, Cloneable, Iterable<String>, Serializable
Direct Known Subclasses:
ConsumableItem, Money, NoStatsStackableItem, Scroll, Seed, TimedStackableItem

public class StackableItem extends Item implements Stackable<StackableItem>
  • Constructor Details

    • StackableItem

      public StackableItem(String name, String clazz, String subclass, Map<String,​String> attributes)
    • StackableItem

      public StackableItem(StackableItem item)
      Copy constructor.
      Parameters:
      item - item to copy
  • Method Details

    • update

      public void update()
      Overrides:
      update in class Entity
    • getQuantity

      public int getQuantity()
      Description copied from class: Item
      Get item count.
      Specified by:
      getQuantity in interface Stackable<StackableItem>
      Overrides:
      getQuantity in class Item
      Returns:
      1.
    • setQuantity

      public void setQuantity(int amount)
      Description copied from interface: Stackable
      sets the quantity.
      Specified by:
      setQuantity in interface Stackable<StackableItem>
      Parameters:
      amount - to be set
    • sub

      public int sub(int amount)
      Reduces Item's amount by amount.
      Parameters:
      amount - of reduction, negative numbers will be ignored.
      Returns:
      remaining amount
    • add

      public int add(StackableItem other)
      Description copied from interface: Stackable
      Adds the quantity of the other Stackable to this.
      Specified by:
      add in interface Stackable<StackableItem>
      Parameters:
      other - other object to merge in
      Returns:
      the previous quantity
    • splitOff

      public StackableItem splitOff(int amountToSplitOff)
    • removeOne

      public void removeOne()
      Description copied from class: Item
      Removes the item. In case of StackableItems only one is removed.
      Overrides:
      removeOne in class Item
    • isStackable

      public boolean isStackable(StackableItem onTop)
      Description copied from interface: Stackable
      checks if the other object can be stacked onto this one
      Specified by:
      isStackable in interface Stackable<StackableItem>
      Parameters:
      onTop - other object
      Returns:
      true when both stackables are of the same type and can be merged
    • getCapacity

      public int getCapacity()
      Description copied from interface: Stackable
      gets the maximum amount
      Specified by:
      getCapacity in interface Stackable<StackableItem>
      Returns:
      the maximum amount
    • setCapacity

      public void setCapacity(int capacity)
      Description copied from interface: Stackable
      sets the maximum amount
      Specified by:
      setCapacity in interface Stackable<StackableItem>