Class ArcaneItemNamingUtil

java.lang.Object
johnsmith.enchantingoverhauled.api.item.ArcaneItemNamingUtil

public final class ArcaneItemNamingUtil extends Object
Utility class responsible for resolving and formatting dynamic arcane item and entity names based on their dominant EnchantmentTheme and MagicSchool.

Supports both explicit attribution (persisted via DataComponents.CUSTOM_DATA NBT keys) and automatic weighted derivation from an item's stored or applied enchantments, producing localized names such as "<Theme> <Item Name> of <School>" or "Aberrant <Item Name>".

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The custom NBT key used within DataComponents.CUSTOM_DATA to store an item's explicit MagicSchool resource location.
    static final String
    The custom NBT key used within DataComponents.CUSTOM_DATA to store an item's explicit EnchantmentTheme resource location.
  • Method Summary

    Modifier and Type
    Method
    Description
    static net.minecraft.network.chat.Component
    formatItemName(net.minecraft.world.item.ItemStack stack, net.minecraft.network.chat.Component baseItemName)
    Formats the display name of an arcane item (such as an Enchanted Book, Enchanted Page, or Enchanted Tome) or entity using its resolved EnchantmentTheme prefix and MagicSchool suffix.
    static @Nullable net.minecraft.core.RegistryAccess
    Retrieves the currently active RegistryAccess, preferring the logical client's registry access if available and falling back to the server's registry access.
    static net.minecraft.network.chat.MutableComponent
    getFormattedSchoolComponent(net.minecraft.resources.ResourceKey<MagicSchool> schoolKey, @Nullable net.minecraft.core.RegistryAccess registryAccess)
    Builds a localized, color-styled MutableComponent representing the given MagicSchool.
    static net.minecraft.network.chat.MutableComponent
    getFormattedThemeComponent(net.minecraft.resources.ResourceKey<EnchantmentTheme> themeKey, @Nullable net.minecraft.core.RegistryAccess registryAccess)
    Builds a localized, color-styled MutableComponent representing the given EnchantmentTheme.
    static Optional<net.minecraft.resources.ResourceKey<MagicSchool>>
    resolveSchool(net.minecraft.world.item.ItemStack stack, @Nullable net.minecraft.core.RegistryAccess registryAccess)
    Resolves the dominant MagicSchool for the given ItemStack.
    static Optional<net.minecraft.resources.ResourceKey<EnchantmentTheme>>
    resolveTheme(net.minecraft.world.item.ItemStack stack, @Nullable net.minecraft.core.RegistryAccess registryAccess)
    Resolves the dominant EnchantmentTheme for the given ItemStack.
    static void
    setClientRegistryAccessSupplier(Supplier<net.minecraft.core.RegistryAccess> supplier)
    Sets the supplier used to retrieve the client's active RegistryAccess.
    static void
    setExplicitAttribution(net.minecraft.world.item.ItemStack stack, @Nullable net.minecraft.resources.ResourceKey<EnchantmentTheme> themeKey, @Nullable net.minecraft.resources.ResourceKey<MagicSchool> schoolKey)
    Writes explicit EnchantmentTheme and MagicSchool attribution keys into the given ItemStack's DataComponents.CUSTOM_DATA component.
    static void
    setServerRegistryAccess(@Nullable net.minecraft.core.RegistryAccess registryAccess)
    Updates the weak reference to the server's active RegistryAccess.

    Methods inherited from class java.lang.Object

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

    • NBT_THEME_KEY

      public static final String NBT_THEME_KEY
      The custom NBT key used within DataComponents.CUSTOM_DATA to store an item's explicit EnchantmentTheme resource location.
      See Also:
    • NBT_SCHOOL_KEY

      public static final String NBT_SCHOOL_KEY
      The custom NBT key used within DataComponents.CUSTOM_DATA to store an item's explicit MagicSchool resource location.
      See Also:
  • Method Details

    • setServerRegistryAccess

      public static void setServerRegistryAccess(@Nullable @Nullable net.minecraft.core.RegistryAccess registryAccess)
      Updates the weak reference to the server's active RegistryAccess.
      Parameters:
      registryAccess - The server's RegistryAccess, or null to clear.
    • setClientRegistryAccessSupplier

      public static void setClientRegistryAccessSupplier(Supplier<net.minecraft.core.RegistryAccess> supplier)
      Sets the supplier used to retrieve the client's active RegistryAccess.
      Parameters:
      supplier - A non-null supplier returning the client's RegistryAccess or null.
    • getActiveRegistryAccess

      @Nullable public static @Nullable net.minecraft.core.RegistryAccess getActiveRegistryAccess()
      Retrieves the currently active RegistryAccess, preferring the logical client's registry access if available and falling back to the server's registry access.
      Returns:
      The active RegistryAccess, or null if neither is available.
    • setExplicitAttribution

      public static void setExplicitAttribution(net.minecraft.world.item.ItemStack stack, @Nullable @Nullable net.minecraft.resources.ResourceKey<EnchantmentTheme> themeKey, @Nullable @Nullable net.minecraft.resources.ResourceKey<MagicSchool> schoolKey)
      Writes explicit EnchantmentTheme and MagicSchool attribution keys into the given ItemStack's DataComponents.CUSTOM_DATA component.

      Passing null for either key removes that specific attribution tag from the item stack.

      Parameters:
      stack - The ItemStack to modify.
      themeKey - The explicit EnchantmentTheme key to assign, or null to remove.
      schoolKey - The explicit MagicSchool key to assign, or null to remove.
    • resolveTheme

      public static Optional<net.minecraft.resources.ResourceKey<EnchantmentTheme>> resolveTheme(net.minecraft.world.item.ItemStack stack, @Nullable @Nullable net.minecraft.core.RegistryAccess registryAccess)
      Resolves the dominant EnchantmentTheme for the given ItemStack.

      First checks for an explicit non-common theme stored in DataComponents.CUSTOM_DATA. If none is found (or if the item has enchantments that override a default common tag), it tallies the enchantment levels per theme across the item's enchantments and returns the non-common theme with the highest cumulative level weight, falling back to EnchantmentThemes.COMMON.

      Parameters:
      stack - The ItemStack to inspect.
      registryAccess - The RegistryAccess used to look up theme tags, or null to use the active fallback.
      Returns:
      An Optional containing the resolved EnchantmentTheme key, or empty if unenchanted and untagged.
    • resolveSchool

      public static Optional<net.minecraft.resources.ResourceKey<MagicSchool>> resolveSchool(net.minecraft.world.item.ItemStack stack, @Nullable @Nullable net.minecraft.core.RegistryAccess registryAccess)
      Resolves the dominant MagicSchool for the given ItemStack.

      First checks for an explicit non-aberration school stored in DataComponents.CUSTOM_DATA. Otherwise, tallies the enchantment levels per school across the item's enchantments and returns the standard school with the highest cumulative level weight, falling back to MagicSchools.ABERRATION.

      Parameters:
      stack - The ItemStack to inspect.
      registryAccess - The RegistryAccess used to look up school tags, or null to use the active fallback.
      Returns:
      An Optional containing the resolved MagicSchool key, or empty if unenchanted and untagged.
    • formatItemName

      public static net.minecraft.network.chat.Component formatItemName(net.minecraft.world.item.ItemStack stack, net.minecraft.network.chat.Component baseItemName)
      Formats the display name of an arcane item (such as an Enchanted Book, Enchanted Page, or Enchanted Tome) or entity using its resolved EnchantmentTheme prefix and MagicSchool suffix.

      Depending on whether the resolved theme is special (non-common) and whether the resolved school is standard or aberrant, formats the name using one of four translation templates:

      • item.enchanting_overhauled.named.themed_school ("<Theme> <Base Name> of <School>")
      • item.enchanting_overhauled.named.school_only ("<Base Name> of <School>")
      • item.enchanting_overhauled.named.aberrant_themed ("Aberrant <Theme> <Base Name>")
      • item.enchanting_overhauled.named.aberrant_only ("Aberrant <Base Name>")
      Parameters:
      stack - The ItemStack whose enchantments and attribution determine the name.
      baseItemName - The unformatted base Component name of the item or entity.
      Returns:
      The formatted Component with colored theme and school segments, or baseItemName if unattributed.
    • getFormattedThemeComponent

      public static net.minecraft.network.chat.MutableComponent getFormattedThemeComponent(net.minecraft.resources.ResourceKey<EnchantmentTheme> themeKey, @Nullable @Nullable net.minecraft.core.RegistryAccess registryAccess)
      Builds a localized, color-styled MutableComponent representing the given EnchantmentTheme.
      Parameters:
      themeKey - The ResourceKey of the theme to format.
      registryAccess - The RegistryAccess to query for theme metadata and color, or null.
      Returns:
      A styled MutableComponent for the theme name.
    • getFormattedSchoolComponent

      public static net.minecraft.network.chat.MutableComponent getFormattedSchoolComponent(net.minecraft.resources.ResourceKey<MagicSchool> schoolKey, @Nullable @Nullable net.minecraft.core.RegistryAccess registryAccess)
      Builds a localized, color-styled MutableComponent representing the given MagicSchool.
      Parameters:
      schoolKey - The ResourceKey of the magic school to format.
      registryAccess - The RegistryAccess to query for school metadata and color, or null.
      Returns:
      A styled MutableComponent for the magic school name.