Class ArcaneItemNamingUtil
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
FieldsModifier and TypeFieldDescriptionstatic final StringThe custom NBT key used withinDataComponents.CUSTOM_DATAto store an item's explicitMagicSchoolresource location.static final StringThe custom NBT key used withinDataComponents.CUSTOM_DATAto store an item's explicitEnchantmentThemeresource location. -
Method Summary
Modifier and TypeMethodDescriptionstatic net.minecraft.network.chat.ComponentformatItemName(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 resolvedEnchantmentThemeprefix andMagicSchoolsuffix.static @Nullable net.minecraft.core.RegistryAccessRetrieves the currently activeRegistryAccess, preferring the logical client's registry access if available and falling back to the server's registry access.static net.minecraft.network.chat.MutableComponentgetFormattedSchoolComponent(net.minecraft.resources.ResourceKey<MagicSchool> schoolKey, @Nullable net.minecraft.core.RegistryAccess registryAccess) Builds a localized, color-styledMutableComponentrepresenting the givenMagicSchool.static net.minecraft.network.chat.MutableComponentgetFormattedThemeComponent(net.minecraft.resources.ResourceKey<EnchantmentTheme> themeKey, @Nullable net.minecraft.core.RegistryAccess registryAccess) Builds a localized, color-styledMutableComponentrepresenting the givenEnchantmentTheme.static Optional<net.minecraft.resources.ResourceKey<MagicSchool>> resolveSchool(net.minecraft.world.item.ItemStack stack, @Nullable net.minecraft.core.RegistryAccess registryAccess) Resolves the dominantMagicSchoolfor the givenItemStack.static Optional<net.minecraft.resources.ResourceKey<EnchantmentTheme>> resolveTheme(net.minecraft.world.item.ItemStack stack, @Nullable net.minecraft.core.RegistryAccess registryAccess) Resolves the dominantEnchantmentThemefor the givenItemStack.static voidsetClientRegistryAccessSupplier(Supplier<net.minecraft.core.RegistryAccess> supplier) Sets the supplier used to retrieve the client's activeRegistryAccess.static voidsetExplicitAttribution(net.minecraft.world.item.ItemStack stack, @Nullable net.minecraft.resources.ResourceKey<EnchantmentTheme> themeKey, @Nullable net.minecraft.resources.ResourceKey<MagicSchool> schoolKey) Writes explicitEnchantmentThemeandMagicSchoolattribution keys into the givenItemStack'sDataComponents.CUSTOM_DATAcomponent.static voidsetServerRegistryAccess(@Nullable net.minecraft.core.RegistryAccess registryAccess) Updates the weak reference to the server's activeRegistryAccess.
-
Field Details
-
NBT_THEME_KEY
The custom NBT key used withinDataComponents.CUSTOM_DATAto store an item's explicitEnchantmentThemeresource location.- See Also:
-
NBT_SCHOOL_KEY
The custom NBT key used withinDataComponents.CUSTOM_DATAto store an item's explicitMagicSchoolresource 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 activeRegistryAccess.- Parameters:
registryAccess- The server'sRegistryAccess, ornullto clear.
-
setClientRegistryAccessSupplier
public static void setClientRegistryAccessSupplier(Supplier<net.minecraft.core.RegistryAccess> supplier) Sets the supplier used to retrieve the client's activeRegistryAccess.- Parameters:
supplier- A non-null supplier returning the client'sRegistryAccessornull.
-
getActiveRegistryAccess
@Nullable public static @Nullable net.minecraft.core.RegistryAccess getActiveRegistryAccess()Retrieves the currently activeRegistryAccess, preferring the logical client's registry access if available and falling back to the server's registry access.- Returns:
- The active
RegistryAccess, ornullif 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 explicitEnchantmentThemeandMagicSchoolattribution keys into the givenItemStack'sDataComponents.CUSTOM_DATAcomponent.Passing
nullfor either key removes that specific attribution tag from the item stack.- Parameters:
stack- TheItemStackto modify.themeKey- The explicitEnchantmentThemekey to assign, ornullto remove.schoolKey- The explicitMagicSchoolkey to assign, ornullto 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 dominantEnchantmentThemefor the givenItemStack.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 toEnchantmentThemes.COMMON.- Parameters:
stack- TheItemStackto inspect.registryAccess- TheRegistryAccessused to look up theme tags, ornullto use the active fallback.- Returns:
- An
Optionalcontaining the resolvedEnchantmentThemekey, 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 dominantMagicSchoolfor the givenItemStack.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 toMagicSchools.ABERRATION.- Parameters:
stack- TheItemStackto inspect.registryAccess- TheRegistryAccessused to look up school tags, ornullto use the active fallback.- Returns:
- An
Optionalcontaining the resolvedMagicSchoolkey, 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 resolvedEnchantmentThemeprefix andMagicSchoolsuffix.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- TheItemStackwhose enchantments and attribution determine the name.baseItemName- The unformatted baseComponentname of the item or entity.- Returns:
- The formatted
Componentwith colored theme and school segments, orbaseItemNameif 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-styledMutableComponentrepresenting the givenEnchantmentTheme.- Parameters:
themeKey- TheResourceKeyof the theme to format.registryAccess- TheRegistryAccessto query for theme metadata and color, ornull.- Returns:
- A styled
MutableComponentfor 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-styledMutableComponentrepresenting the givenMagicSchool.- Parameters:
schoolKey- TheResourceKeyof the magic school to format.registryAccess- TheRegistryAccessto query for school metadata and color, ornull.- Returns:
- A styled
MutableComponentfor the magic school name.
-