Class AmountModifier

java.lang.Object
io.github.projectunified.craftitem.modifier.AmountModifier
All Implemented Interfaces:
ItemModifier

public class AmountModifier extends Object implements ItemModifier
Item modifier that sets the item's stack amount.

The amount can be provided as an integer, string, or defaults to 1. The string value is translated before parsing to support dynamic amounts.

Example Usage:


 // Direct integer amount
 ItemModifier modifier1 = new AmountModifier(64);

 // String amount with variables
 ItemModifier modifier2 = new AmountModifier("${stack_size}");
 modifier2.modify(item, s -> s.replace("${stack_size}", "32"));

 // Default amount of 1
 ItemModifier modifier3 = new AmountModifier();
 
  • Constructor Details

    • AmountModifier

      public AmountModifier(int amount)
      Creates a new AmountModifier with the specified integer amount.
      Parameters:
      amount - the stack size
    • AmountModifier

      public AmountModifier(String amount)
      Creates a new AmountModifier with the specified string amount. The string can contain variables for translation.
      Parameters:
      amount - the stack size as a string
    • AmountModifier

      public AmountModifier()
      Creates a new AmountModifier with a default amount of 1.
  • Method Details

    • modify

      public void modify(Item item, UnaryOperator<String> translator)
      Applies the translated amount to the item. Invalid amounts are silently ignored.
      Specified by:
      modify in interface ItemModifier
      Parameters:
      item - the item to modify
      translator - the string translator for variable substitution