Class SetCountFunction
java.lang.Object
com.github.darksoulq.abyssallib.world.data.loot.LootFunction
com.github.darksoulq.abyssallib.world.data.loot.function.SetCountFunction
A loot function that modifies the stack size of a generated item to a random value within a specified range.
This is the standard function used to provide variety in loot drops, allowing a single loot entry to represent a quantity range (e.g., 1-3 diamonds) rather than a fixed amount.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Codec<SetCountFunction> The codec used for serializing and deserializing the set count function.static final LootFunctionType<SetCountFunction> The registered type definition for the set count loot function. -
Constructor Summary
ConstructorsConstructorDescriptionSetCountFunction(int min, int max) Constructs a new SetCountFunction with a specified range. -
Method Summary
Modifier and TypeMethodDescriptionorg.bukkit.inventory.ItemStackapply(org.bukkit.inventory.ItemStack stack, LootContext context) Randomizes the amount of the providedItemStackbased on the defined range.getType()Retrieves the specific type definition for this loot function.
-
Field Details
-
CODEC
The codec used for serializing and deserializing the set count function.It requires "min" and "max" integer fields to define the inclusive range for the random generation.
-
TYPE
The registered type definition for the set count loot function.
-
-
Constructor Details
-
SetCountFunction
public SetCountFunction(int min, int max) Constructs a new SetCountFunction with a specified range.- Parameters:
min- The minimum possible stack size (inclusive).max- The maximum possible stack size (inclusive).
-
-
Method Details
-
apply
public org.bukkit.inventory.ItemStack apply(org.bukkit.inventory.ItemStack stack, LootContext context) Randomizes the amount of the providedItemStackbased on the defined range.The new amount is calculated using the
Randominstance provided by theLootContext.- Specified by:
applyin classLootFunction- Parameters:
stack- TheItemStackgenerated by the loot entry.context- TheLootContextproviding the random source.- Returns:
- The modified
ItemStackwith its new randomized amount.
-
getType
Retrieves the specific type definition for this loot function.- Specified by:
getTypein classLootFunction- Returns:
- The
LootFunctionTypeassociated withSetCountFunction.
-