Class LimitCountFunction

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

public class LimitCountFunction extends LootFunction
A loot function that clamps the stack size of a generated item within a specified minimum and maximum range.

This function is useful for ensuring that randomized loot amounts (generated by previous functions like SetCountFunction) do not exceed or fall below certain balanced thresholds.

  • Field Details

    • CODEC

      public static final Codec<LimitCountFunction> CODEC
      The codec used for serializing and deserializing the limit count function.

      It maps the "min" and "max" integer fields. If missing, "min" defaults to 0 and "max" defaults to Integer.MAX_VALUE.

    • TYPE

      public static final LootFunctionType<LimitCountFunction> TYPE
      The registered type definition for the limit count loot function.
  • Constructor Details

    • LimitCountFunction

      public LimitCountFunction(int min, int max)
      Constructs a new LimitCountFunction with specific bounds.
      Parameters:
      min - The inclusive minimum amount.
      max - The inclusive maximum amount.
  • Method Details

    • apply

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

      The method retrieves the current stack amount and constrains it such that min <= amount <= max.

      * @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 environmental data.
      Returns:
      The modified ItemStack with its amount clamped to the defined range.
    • getType

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