Class SetDamageFunction
java.lang.Object
com.github.darksoulq.abyssallib.world.data.loot.LootFunction
com.github.darksoulq.abyssallib.world.data.loot.function.SetDamageFunction
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final Codec<SetDamageFunction> The codec used for serializing and deserializing the set damage function.static final LootFunctionType<SetDamageFunction> The registered type definition for the set damage loot function. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.bukkit.inventory.ItemStackapply(org.bukkit.inventory.ItemStack stack, LootContext context) Applies the randomized damage to the providedItemStack.getType()Retrieves the specific type definition for this loot function.
-
Field Details
-
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
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 providedItemStack.This method calculates the damage based on either the material's default maximum durability or the value defined in the
DataComponentTypes.MAX_DAMAGEcomponent if present.- Specified by:
applyin classLootFunction- Parameters:
stack- TheItemStackgenerated by the loot entry.context- TheLootContextproviding the random source.- Returns:
- The modified
ItemStackwith the randomized damage value applied.
-
getType
Retrieves the specific type definition for this loot function.- Specified by:
getTypein classLootFunction- Returns:
- The
LootFunctionTypeassociated withSetDamageFunction.
-