Package net.xun.lib.common.api.util
Class CommonUtils
java.lang.Object
net.xun.lib.common.api.util.CommonUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringcombineAsNamespacedID(String namespace, String... pathParts) Combines a namespace with path components into a namespaced ID string.static net.minecraft.resources.ResourceLocationRetrieves the registry key for a given object by checking known registries.static StringgetRegistryID(Object obj) Gets the path component of the registry key for the given object.static StringgetRegistryID(net.minecraft.world.level.ItemLike itemLike) Gets the path component of the registry key for anItemLikeobject.static net.minecraft.resources.ResourceLocationmodResourceLocation(String path) Creates a ResourceLocation using the auto-detected or manually set mod ID.static StringnamespacedID(String... pathParts) Generates a namespaced ID string using the current mod ID.
-
Method Details
-
combineAsNamespacedID
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
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
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
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
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
Gets the path component of the registry key for anItemLikeobject.Specifically handles items and blocks through the
ItemLikeinterface.- 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:
-