Class SetDamageFunction

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

public class SetDamageFunction extends LootFunction
A loot function that sets the damage (durability loss) of a generated item based on a percentage range.

The damage is calculated as a percentage of the item's maximum durability. For example, a range of 0.1 to 0.5 would result in an item missing 10% to 50% of its total durability.

  • Field Details

    • CODEC

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

      It requires "min" and "max" float fields representing the damage percentage range (0.0 to 1.0).

    • TYPE

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

    • SetDamageFunction

      public SetDamageFunction(float min, float max)
      Constructs a new SetDamageFunction.
      Parameters:
      min - The minimum damage percentage (0.0 - 1.0).
      max - The maximum damage percentage (0.0 - 1.0).
  • Method Details

    • apply

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

      This method calculates the damage based on either the material's default maximum durability or the value defined in the DataComponentTypes.MAX_DAMAGE component if present.

      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 the randomized damage value applied.
    • getType

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