Class SetCountFunction

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

public class SetCountFunction extends LootFunction
A loot function that modifies the stack size of a generated item to a random value within a specified range.

This is the standard function used to provide variety in loot drops, allowing a single loot entry to represent a quantity range (e.g., 1-3 diamonds) rather than a fixed amount.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Codec<SetCountFunction>
    The codec used for serializing and deserializing the set count function.
    The registered type definition for the set count loot function.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SetCountFunction(int min, int max)
    Constructs a new SetCountFunction with a specified range.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.bukkit.inventory.ItemStack
    apply(org.bukkit.inventory.ItemStack stack, LootContext context)
    Randomizes the amount of the provided ItemStack based on the defined range.
    Retrieves the specific type definition for this loot function.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • CODEC

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

      It requires "min" and "max" integer fields to define the inclusive range for the random generation.

    • TYPE

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

    • SetCountFunction

      public SetCountFunction(int min, int max)
      Constructs a new SetCountFunction with a specified range.
      Parameters:
      min - The minimum possible stack size (inclusive).
      max - The maximum possible stack size (inclusive).
  • Method Details

    • apply

      public org.bukkit.inventory.ItemStack apply(org.bukkit.inventory.ItemStack stack, LootContext context)
      Randomizes the amount of the provided ItemStack based on the defined range.

      The new amount is calculated using the Random instance provided by the LootContext.

      Specified by:
      apply in class LootFunction
      Parameters:
      stack - The ItemStack generated by the loot entry.
      context - The LootContext providing the random source.
      Returns:
      The modified ItemStack with its new randomized amount.
    • getType

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