Class SetNameFunction

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

public class SetNameFunction extends LootFunction
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

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

    Constructors
    Constructor
    Description
    SetNameFunction(net.kyori.adventure.text.Component name)
    Constructs a new SetNameFunction with a specific component.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.bukkit.inventory.ItemStack
    apply(org.bukkit.inventory.ItemStack stack, LootContext context)
    Applies the custom name to the provided ItemStack.
    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<SetNameFunction> CODEC
      The codec used for serializing and deserializing the set name function.

      It maps the "name" field to a serialized Adventure Component.

    • TYPE

      public static final LootFunctionType<SetNameFunction> 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 - The Component to 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 provided ItemStack.

      This method directly sets the DataComponentTypes.CUSTOM_NAME data on the stack using the configured component.

      Specified by:
      apply in class LootFunction
      Parameters:
      stack - The ItemStack generated by the loot entry.
      context - The LootContext providing environmental data.
      Returns:
      The modified ItemStack with the new custom name 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 SetNameFunction.