Class LimitCountFunction
java.lang.Object
com.github.darksoulq.abyssallib.world.data.loot.LootFunction
com.github.darksoulq.abyssallib.world.data.loot.function.LimitCountFunction
A loot function that clamps the stack size of a generated item within a specified minimum and maximum range.
This function is useful for ensuring that randomized loot amounts (generated by previous functions
like SetCountFunction) do not exceed or fall below certain balanced thresholds.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Codec<LimitCountFunction> The codec used for serializing and deserializing the limit count function.static final LootFunctionType<LimitCountFunction> The registered type definition for the limit count loot function. -
Constructor Summary
ConstructorsConstructorDescriptionLimitCountFunction(int min, int max) Constructs a new LimitCountFunction with specific bounds. -
Method Summary
Modifier and TypeMethodDescriptionorg.bukkit.inventory.ItemStackapply(org.bukkit.inventory.ItemStack stack, LootContext context) Applies the clamping logic to the providedItemStack.getType()Retrieves the specific type definition for this loot function.
-
Field Details
-
CODEC
The codec used for serializing and deserializing the limit count function.It maps the "min" and "max" integer fields. If missing, "min" defaults to 0 and "max" defaults to
Integer.MAX_VALUE. -
TYPE
The registered type definition for the limit count loot function.
-
-
Constructor Details
-
LimitCountFunction
public LimitCountFunction(int min, int max) Constructs a new LimitCountFunction with specific bounds.- Parameters:
min- The inclusive minimum amount.max- The inclusive maximum amount.
-
-
Method Details
-
apply
public org.bukkit.inventory.ItemStack apply(org.bukkit.inventory.ItemStack stack, LootContext context) Applies the clamping logic to the providedItemStack.The method retrieves the current stack amount and constrains it such that
* @param stack Themin <= amount <= max.ItemStackgenerated by the loot entry.- Specified by:
applyin classLootFunction- Parameters:
stack- TheItemStackto be modified.context- TheLootContextproviding environmental data.- Returns:
- The modified
ItemStackwith its amount clamped to the defined range.
-
getType
Retrieves the specific type definition for this loot function. * @return TheLootFunctionTypeassociated withLimitCountFunction.- Specified by:
getTypein classLootFunction- Returns:
- The
LootFunctionTypeused for registry identification and serialization.
-