Class EnchantRandomlyFunction
java.lang.Object
com.github.darksoulq.abyssallib.world.data.loot.LootFunction
com.github.darksoulq.abyssallib.world.data.loot.function.EnchantRandomlyFunction
A loot function that applies a random enchantment to the generated item.
If a list of enchantments is provided, the function will pick one at random from that list. If the list is empty, it will pick from all enchantments registered in the game that are compatible with the item being enchanted.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Codec<EnchantRandomlyFunction> The codec used for serializing and deserializing this function's configuration.static final LootFunctionType<EnchantRandomlyFunction> The registered type definition for this loot function. -
Constructor Summary
ConstructorsConstructorDescriptionEnchantRandomlyFunction(List<String> enchantments) Constructs a new EnchantRandomlyFunction. -
Method Summary
Modifier and TypeMethodDescriptionorg.bukkit.inventory.ItemStackapply(org.bukkit.inventory.ItemStack stack, LootContext context) Applies a random enchantment to the providedItemStack.getType()Retrieves the specific type definition associated with this function.
-
Field Details
-
CODEC
The codec used for serializing and deserializing this function's configuration. -
TYPE
The registered type definition for this loot function.
-
-
Constructor Details
-
EnchantRandomlyFunction
-
-
Method Details
-
apply
public org.bukkit.inventory.ItemStack apply(org.bukkit.inventory.ItemStack stack, LootContext context) Applies a random enchantment to the providedItemStack.This method handles both standard items (using
DataComponentTypes.ENCHANTMENTS) and enchanted books (usingDataComponentTypes.STORED_ENCHANTMENTS). It randomly selects a level between 1 and the enchantment's max level.- Specified by:
applyin classLootFunction- Parameters:
stack- TheItemStackgenerated by the loot pool.context- TheLootContextproviding the random source and environmental data.- Returns:
- The modified
ItemStackwith a new enchantment applied.
-
getType
Description copied from class:LootFunctionRetrieves the specific type definition associated with this function.- Specified by:
getTypein classLootFunction- Returns:
- The
LootFunctionTypeassociated with this function.
-