Class ExplosionDecayFunction

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

public class ExplosionDecayFunction extends LootFunction
A loot function that reduces the amount of items in a stack based on an explosion decay algorithm.

This function simulates the destruction of loot that occurs when a block is broken by an explosion, where each individual item in the stack has a probability of being "destroyed" and removed.

  • Field Details

    • CODEC

      public static final Codec<ExplosionDecayFunction> CODEC
      The codec used for serializing and deserializing the explosion decay function.

      Since this function maintains no state or configuration parameters, it decodes from and encodes to an empty map structure.

    • TYPE

      public static final LootFunctionType<ExplosionDecayFunction> TYPE
      The registered type definition for this loot function.
  • Constructor Details

    • ExplosionDecayFunction

      public ExplosionDecayFunction()
  • Method Details

    • apply

      public org.bukkit.inventory.ItemStack apply(org.bukkit.inventory.ItemStack stack, LootContext context)
      Applies the explosion decay logic to the provided ItemStack.

      Each item in the original stack is subjected to a random roll against a decay threshold derived from the context's random source. Items that fail the roll are discarded, and the stack's final amount is updated to the remaining count.

      * @param stack The ItemStack generated by the loot entry.
      Specified by:
      apply in class LootFunction
      Parameters:
      stack - The ItemStack to be modified.
      context - The LootContext providing the random source and environmental data.
      Returns:
      The modified ItemStack with the updated (and potentially reduced) amount.
    • getType

      public LootFunctionType<?> getType()
      Retrieves the specific type definition for this loot function. * @return The LootFunctionType associated with ExplosionDecayFunction.
      Specified by:
      getType in class LootFunction
      Returns:
      The LootFunctionType used for registry identification and serialization.