Class LootingEnchantFunction

java.lang.Object
com.github.darksoulq.abyssallib.world.data.loot.LootFunction
com.github.darksoulq.abyssallib.world.data.loot.function.LootingEnchantFunction

public class LootingEnchantFunction extends LootFunction
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 Details

    • CODEC

      public static final Codec<LootingEnchantFunction> 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

      public static final LootFunctionType<LootingEnchantFunction> 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 provided ItemStack.

      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 the limit.

      Specified by:
      apply in class LootFunction
      Parameters:
      stack - The ItemStack generated by the loot entry.
      context - The LootContext providing the killer, tool, and random source.
      Returns:
      The modified ItemStack with its amount potentially increased by looting.
    • getType

      public LootFunctionType<?> getType()
      Retrieves the specific type definition for this loot function.
      Specified by:
      getType in class LootFunction
      Returns:
      The LootFunctionType associated with LootingEnchantFunction.