mcfonts.path

Utilities for working with paths and resource locations.

A resource location is a string used to reference blocks, items, entity types, and various other objects in normal Minecraft. A valid resource location has a format of namespace:path.

Module Contents

class BedrockPackRoot

Bases: PackRoot

Bedrock Edition resource pack root.

__fspath__() str

Return absolute file path as string.

Return type:

str

__str__() str
Return type:

str

classmethod from_path(path: pathlib.Path, /) BedrockPackRoot

Return a pack root, given a path to any resource within the pack.

Parameters:
path : pathlib.Path

The Path, can deeply nested and to any resource.

Returns:

A PackRoot.

Return type:

BedrockPackRoot

get(resource_location: str, /, object_type: str | None = None) pathlib.Path

Return the path to any location, given its resource location.

Parameters:
resource_location : str

The resource location.

object_type : str | None

Optional override for which folder in namespace to subpath under.

Returns:

A Path.

Return type:

pathlib.Path

get_alt(resource_location: str, /) pathlib.Path

Alternate form for [NAMESPACE]:COMPONENT/SUBPATH.

Parameters:
resource_location : str

Return type:

pathlib.Path

path_to_resource_location(path: pathlib.Path, /) str
Parameters:
path : pathlib.Path

Return type:

str

class JavaPackRoot

Bases: PackRoot

Java Edition resource pack root.

__fspath__() str

Return absolute file path as string.

Return type:

str

__str__() str
Return type:

str

classmethod from_path(path: pathlib.Path, /) JavaPackRoot

Return a PackPath from an arbitrary path to a file inside a resource pack.

Parameters:
path : pathlib.Path

Path to file in resource pack.

Returns:

Instance of this.

Raises:

ValueError -- If no 'assets' folder was found.

Return type:

JavaPackRoot

get(resource_location: str, /, object_type: str | None = None) pathlib.Path

Return the path to any location, given its resource location.

Parameters:
resource_location : str

The resource location.

object_type : str | None

Optional override for which folder in namespace to subpath under.

Returns:

A Path.

Return type:

pathlib.Path

get_alt(resource_location: str, /) pathlib.Path

Alternate form for [NAMESPACE]:COMPONENT/SUBPATH.

Parameters:
resource_location : str

Return type:

pathlib.Path

path_to_resource_location(path: pathlib.Path, /) str
Parameters:
path : pathlib.Path

Return type:

str

default_namespace : ClassVar[str] = 'minecraft'
path : pathlib.Path
valid_chars : ClassVar[str] = 'abcdefghijklmnopqrstuvwxyz0123456789_-.'
class PackRoot

Bases: os.PathLike[str], abc.ABC

A pack root is a path to the root of a resource pack.

abstractmethod __fspath__() str

Return absolute file path as string.

Return type:

str

classmethod from_path(path: pathlib.Path, /) PackRoot
Abstractmethod:

Parameters:
path : pathlib.Path

Return type:

PackRoot

Return a pack root, given a path to any resource within the pack.

Parameters:
path : pathlib.Path

The Path, can deeply nested and to any resource.

Returns:

A PackRoot.

Return type:

PackRoot

abstractmethod get(resource_location: str, /, object_type: str | None = None) pathlib.Path

Return the path to any location, given its resource location.

Parameters:
resource_location : str

The resource location.

object_type : str | None

Optional override for which folder in namespace to subpath under.

Returns:

A Path.

Return type:

pathlib.Path

abstractmethod get_alt(resource_location: str, /) pathlib.Path

Alternate form for [NAMESPACE]:COMPONENT/SUBPATH.

Parameters:
resource_location : str

Return type:

pathlib.Path

abstractmethod path_to_resource_location(path: pathlib.Path, /) str
Parameters:
path : pathlib.Path

Return type:

str

split_namespace(resource_location: str, /) tuple[str, str]

Return the namespace and subpath, given a resource location.

Warning

Validation is not performed.

Parameters:
resource_location : str

The resource location.

Returns:

A tuple of (namespace, subpath).

Return type:

tuple[str, str]