Class LootingEnchantFunction
java.lang.Object
com.github.darksoulq.abyssallib.world.data.loot.LootFunction
com.github.darksoulq.abyssallib.world.data.loot.function.LootingEnchantFunction
A loot function that increases the stack size of generated loot based on the Looting enchantment level.
This function checks the tool used by the killer in the LootContext. If the tool has
the Enchantment.LOOTING enchantment, a random bonus amount (between 0 and the enchantment level)
is added to the stack size, up to a defined limit.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Codec<LootingEnchantFunction> The codec used for serializing and deserializing the looting enchantment function.static final LootFunctionType<LootingEnchantFunction> The registered type definition for the looting enchantment loot function. -
Constructor Summary
ConstructorsConstructorDescriptionLootingEnchantFunction(int limit) Constructs a new LootingEnchantFunction with a specific stack size limit. -
Method Summary
Modifier and TypeMethodDescriptionorg.bukkit.inventory.ItemStackapply(org.bukkit.inventory.ItemStack stack, LootContext context) Applies the looting enchantment bonus to the providedItemStack.getType()Retrieves the specific type definition for this loot function.
-
Field Details
-
CODEC
The codec used for serializing and deserializing the looting enchantment function.It maps the "limit" integer field, which defines the maximum stack size allowed after applying the looting bonus.
-
TYPE
The registered type definition for the looting enchantment loot function.
-
-
Constructor Details
-
LootingEnchantFunction
public LootingEnchantFunction(int limit) Constructs a new LootingEnchantFunction with a specific stack size limit.- Parameters:
limit- The maximum amount an item stack can reach via this function. If 0 or less, defaults to 64.
-
-
Method Details
-
apply
public org.bukkit.inventory.ItemStack apply(org.bukkit.inventory.ItemStack stack, LootContext context) Applies the looting enchantment bonus to the providedItemStack.The function requires a valid killer and a tool in the
LootContext. A random integer between 0 and the Looting level (inclusive) is added to the current stack amount, constrained by thelimit.- Specified by:
applyin classLootFunction- Parameters:
stack- TheItemStackgenerated by the loot entry.context- TheLootContextproviding the killer, tool, and random source.- Returns:
- The modified
ItemStackwith its amount potentially increased by looting.
-
getType
Retrieves the specific type definition for this loot function.- Specified by:
getTypein classLootFunction- Returns:
- The
LootFunctionTypeassociated withLootingEnchantFunction.
-