Class CommonUtils

java.lang.Object
net.xun.lib.common.api.util.CommonUtils

public class CommonUtils extends Object
  • Method Details

    • combineAsNamespacedID

      public static String combineAsNamespacedID(String namespace, String... pathParts)
      Combines a namespace with path components into a namespaced ID string.

      The path components are joined with underscores, forming the path part of the ID. The result is formatted as "namespace:joined_path". For example:

      
       combineAsNamespacedID("mymod", "item", "example") // returns "mymod:item_example"
       
      Parameters:
      namespace - The namespace to use (typically a mod ID)
      pathParts - The components of the path to join with underscores
      Returns:
      The combined namespaced ID in standard "namespace:path" format
    • modResourceLocation

      public static net.minecraft.resources.ResourceLocation modResourceLocation(String path)
      Creates a ResourceLocation using the auto-detected or manually set mod ID.
      Parameters:
      path - The resource path (e.g., "items/example")
      Returns:
      Namespaced ResourceLocation
      Throws:
      IllegalStateException - If the mod ID has not been set or detected
    • namespacedID

      public static String namespacedID(String... pathParts)
      Generates a namespaced ID string using the current mod ID.
      Parameters:
      pathParts - The ID path components to join with underscores
      Returns:
      Combined ID string in "namespace:path" format
      Throws:
      IllegalStateException - If the mod ID has not been set or detected
    • getKey

      public static net.minecraft.resources.ResourceLocation getKey(Object obj)
      Retrieves the registry key for a given object by checking known registries.

      Supports objects registered in common registries such as blocks, items, entities, effects, and more. If the object's type isn't recognized, throws an exception.

      Parameters:
      obj - The registered object to get the key for
      Returns:
      The resource location key of the object
      Throws:
      IllegalArgumentException - If the object's type isn't in the supported registries
    • getRegistryID

      public static String getRegistryID(Object obj)
      Gets the path component of the registry key for the given object.

      Equivalent to calling getKey(obj).getPath().

      Parameters:
      obj - The registered object to get the ID for
      Returns:
      The path portion of the object's registry key
      Throws:
      IllegalArgumentException - If the object's type isn't supported
      See Also:
    • getRegistryID

      public static String getRegistryID(net.minecraft.world.level.ItemLike itemLike)
      Gets the path component of the registry key for an ItemLike object.

      Specifically handles items and blocks through the ItemLike interface.

      Parameters:
      itemLike - The item or block to get the registry ID for
      Returns:
      The path portion of the object's registry key
      Throws:
      IllegalArgumentException - If the object's type isn't supported
      See Also: