Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Adding Namespaces

You learned how to create your first datapack. Now we want to add namespaces to that datapack.

Importing Namespaces

To add new namespaces to your datapack you use the Namespace class and the add_namespaces method from the Datapack class. To do this we have to also import the Namespace class from MCpypack.

from MCpypack import Datapack, Namespace

Creating Namespaces

After that we can create a new datapack with a custom name.

my_namespace: Namespace = Namespace(name="my_namespace")

my_pack.add_namespaces(my_namespace)

Note

The name is currently the only argument the class accepts, but it is still recommended to use keyword arguments here.

Of course you can create multiple namespaces.

my_first_namespace: Namespace = Namespace(name="my_first_namespace")
my_second_namespace: Namespace = Namespace(name="my_second_namespace")

my_pack.add_namespaces(
    my_first_namespace,
    my_second_namespace,
)

Note

As you may have noticed we didn’t include any whitespaces ot other special characters in the names of our namespaces. This is because Minecraft has a special set of rules what characters namespace names can include.

Overwriting Game Content

Later you may want to change certain predefined aspects of the game like recipes. To do that you have to create a new namespace named minecraft.

Whole Code

from MCpypack import Datapack, Namespace

my_pack: Datapack = Datapack(
    name="My Datapack",
    description="My first datapack",
    version="26.1"
)

my_namespace: Namespace = Namespace(name="my_namespace")
my_pack.add_namespaces(my_namespace)

my_pack.export()