Class SetNameFunction
java.lang.Object
com.github.darksoulq.abyssallib.world.data.loot.LootFunction
com.github.darksoulq.abyssallib.world.data.loot.function.SetNameFunction
A loot function that overrides the custom display name of a generated item.
This function applies a Component to the DataComponentTypes.CUSTOM_NAME
component type, allowing for full Adventure text support including colors,
styling, and translatable components.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Codec<SetNameFunction> The codec used for serializing and deserializing the set name function.static final LootFunctionType<SetNameFunction> The registered type definition for the set name loot function. -
Constructor Summary
ConstructorsConstructorDescriptionSetNameFunction(net.kyori.adventure.text.Component name) Constructs a new SetNameFunction with a specific component. -
Method Summary
Modifier and TypeMethodDescriptionorg.bukkit.inventory.ItemStackapply(org.bukkit.inventory.ItemStack stack, LootContext context) Applies the custom name 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 name function.It maps the "name" field to a serialized Adventure
Component. -
TYPE
The registered type definition for the set name loot function.
-
-
Constructor Details
-
SetNameFunction
public SetNameFunction(net.kyori.adventure.text.Component name) Constructs a new SetNameFunction with a specific component.- Parameters:
name- TheComponentto use as the item's custom name.
-
-
Method Details
-
apply
public org.bukkit.inventory.ItemStack apply(org.bukkit.inventory.ItemStack stack, LootContext context) Applies the custom name to the providedItemStack.This method directly sets the
DataComponentTypes.CUSTOM_NAMEdata on the stack using the configured component.- Specified by:
applyin classLootFunction- Parameters:
stack- TheItemStackgenerated by the loot entry.context- TheLootContextproviding environmental data.- Returns:
- The modified
ItemStackwith the new custom name applied.
-
getType
Retrieves the specific type definition for this loot function.- Specified by:
getTypein classLootFunction- Returns:
- The
LootFunctionTypeassociated withSetNameFunction.
-