Class AmountModifier
java.lang.Object
io.github.projectunified.craftitem.modifier.AmountModifier
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionCreates a new AmountModifier with a default amount of 1.AmountModifier(int amount) Creates a new AmountModifier with the specified integer amount.AmountModifier(String amount) Creates a new AmountModifier with the specified string amount. -
Method Summary
Modifier and TypeMethodDescriptionvoidmodify(Item item, UnaryOperator<String> translator) Applies the translated amount to the item.
-
Constructor Details
-
AmountModifier
public AmountModifier(int amount) Creates a new AmountModifier with the specified integer amount.- Parameters:
amount- the stack size
-
AmountModifier
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
Applies the translated amount to the item. Invalid amounts are silently ignored.- Specified by:
modifyin interfaceItemModifier- Parameters:
item- the item to modifytranslator- the string translator for variable substitution
-