Package scute

Scute is a Python package designed to make making Minecraft datapacks easier. It allows you to create almost all elements of a datapack with pure code (eventually - at the moment it's just functions and recipes). View the Github or the PyPi listing

Usage

Install the package by doing the following:

pip install scutemc

Then, use the package:

from scute.function import func
from scute.items import Item
from scute.commands import give

@func("namespace", "name")
def myFunc():
    give("@s", Item.green_dye)

(Please note that it is installed with the name scutemc but is imported as scute)

Recommended reading to start off: scute.function, scute.items

Expand source code Browse git
"""
Scute is a Python package designed to make making Minecraft datapacks easier. It allows you to create
almost all elements of a datapack with pure code (eventually - at the moment it's just functions and recipes).
.. include:: ../pdoc/documentation/index.md
"""

import json
import os
import shutil
from os.path import join

_function_namespaces = {}


class pack:
    meta = {"pack": {"pack_format": 1, "description": "My first pack"}}
    name = ""
    path = ""
    namespace = "scute"
    _command_stack = []

    @staticmethod
    def check_valid():
        """
        Checks the validity of your pack, and creates the file structure. Must be run at the top of the file after you define pack.name, etc
        """
        if pack.name != "":
            if pack.path != "":
                bp = join(os.path.expandvars(pack.path), pack.name)
                shutil.rmtree(bp, ignore_errors=True)
                os.makedirs(bp, exist_ok=True)
                try:
                    with open(join(bp, "pack.mcmeta"), "w") as mcmeta:
                        json.dump(pack.meta, mcmeta, indent=4)
                except Exception as e:
                    print("Build path is not valid, or folder does not exist. Error:")
                    print(e)
                    return

                os.makedirs(os.path.join(bp, "data"), exist_ok=True)

            else:
                print("Please set a path to compile to with scute.pack.setBuildPath()")
        else:
            print("Please set a pack name with scute.pack.setName()")

    @staticmethod
    def set_name(name):
        """
        Sets the display name of the pack
        Args:
            name: The name
        """
        pack.name = name

    @staticmethod
    def set_main_namespace(namespace):
        """
        Sets the namespace that will be used for automatically-generated or anonymous functions
        Args:
            namespace: The namespace
        """
        pack.namespace = namespace

    @staticmethod
    def set_description(desc: str):
        """
        Sets the description of your pack
        Args:
            desc: The description
        """
        pack.meta["pack"]["description"] = desc

    @staticmethod
    def set_version(version: str | int):
        """
        Sets the version that the pack supports
        Args:
            version: Can be a major release like "1.19.4" (goes back to 1.16) or a pack_format number like 11
        """
        if isinstance(version, str):
            pack.meta["pack"]["pack_format"] = _versions[version]
        else:
            pack.meta["pack"]["pack_format"] = version

    @staticmethod
    def set_build_path(path: str):
        """
        Sets the folder which your datapack will be built into - for example, "%appdata%/.minecraft/saves/world/datapacks", or "./output"
        """
        pack.path = os.path.expandvars(path)


_versions = {
    "1.16": 5,
    "1.16.1": 5,
    "1.16.2": 6,
    "1.16.3": 6,
    "1.16.4": 6,
    "1.16.5": 6,
    "1.17": 7,
    "1.17.1": 7,
    "1.18": 8,
    "1.18.1": 8,
    "1.18.2": 9,
    "1.19": 10,
    "1.19.1": 10,
    "1.19.2": 10,
    "1.19.3": 10,
    "1.19.4": 12,
    "1.20": 15,
    "1.20.1": 15,
}

Sub-modules

scute.advancements
scute.biomes

Enum for all biomes in Minecraft.

scute.blocks

Enum and class for blocks.

scute.commands

Submodule containing commands and command-related functions

scute.data_sources

Submodule for data sources like block entities, entities, and storage

scute.data_types

Various data types used in NBT.

scute.dimensions

Enum for dimensions

scute.enchantments

Enum for all enchantments in Minecraft.

scute.function
scute.heightmaps

Enum for all heightmaps in Minecraft.

scute.internal
scute.items

Enum for item types, and a class for creating items.

scute.json_text

Submodule for json-formatted text, used in /tellraw or item names etc

scute.recipes

Submodule for creating and managing recipes - shaped crafting, smelting, etc.

scute.relations

Enum for all relations in the game.

scute.scoreboards

Submodule for scoreboards and criteria

scute.tags

Submodule for creating and managing tags - function tags, block tags, item tags, etc.

scute.utils

Classes

class pack
Expand source code Browse git
class pack:
    meta = {"pack": {"pack_format": 1, "description": "My first pack"}}
    name = ""
    path = ""
    namespace = "scute"
    _command_stack = []

    @staticmethod
    def check_valid():
        """
        Checks the validity of your pack, and creates the file structure. Must be run at the top of the file after you define pack.name, etc
        """
        if pack.name != "":
            if pack.path != "":
                bp = join(os.path.expandvars(pack.path), pack.name)
                shutil.rmtree(bp, ignore_errors=True)
                os.makedirs(bp, exist_ok=True)
                try:
                    with open(join(bp, "pack.mcmeta"), "w") as mcmeta:
                        json.dump(pack.meta, mcmeta, indent=4)
                except Exception as e:
                    print("Build path is not valid, or folder does not exist. Error:")
                    print(e)
                    return

                os.makedirs(os.path.join(bp, "data"), exist_ok=True)

            else:
                print("Please set a path to compile to with scute.pack.setBuildPath()")
        else:
            print("Please set a pack name with scute.pack.setName()")

    @staticmethod
    def set_name(name):
        """
        Sets the display name of the pack
        Args:
            name: The name
        """
        pack.name = name

    @staticmethod
    def set_main_namespace(namespace):
        """
        Sets the namespace that will be used for automatically-generated or anonymous functions
        Args:
            namespace: The namespace
        """
        pack.namespace = namespace

    @staticmethod
    def set_description(desc: str):
        """
        Sets the description of your pack
        Args:
            desc: The description
        """
        pack.meta["pack"]["description"] = desc

    @staticmethod
    def set_version(version: str | int):
        """
        Sets the version that the pack supports
        Args:
            version: Can be a major release like "1.19.4" (goes back to 1.16) or a pack_format number like 11
        """
        if isinstance(version, str):
            pack.meta["pack"]["pack_format"] = _versions[version]
        else:
            pack.meta["pack"]["pack_format"] = version

    @staticmethod
    def set_build_path(path: str):
        """
        Sets the folder which your datapack will be built into - for example, "%appdata%/.minecraft/saves/world/datapacks", or "./output"
        """
        pack.path = os.path.expandvars(path)

Class variables

var meta
var name
var namespace
var path

Static methods

def check_valid()

Checks the validity of your pack, and creates the file structure. Must be run at the top of the file after you define pack.name, etc

Expand source code Browse git
@staticmethod
def check_valid():
    """
    Checks the validity of your pack, and creates the file structure. Must be run at the top of the file after you define pack.name, etc
    """
    if pack.name != "":
        if pack.path != "":
            bp = join(os.path.expandvars(pack.path), pack.name)
            shutil.rmtree(bp, ignore_errors=True)
            os.makedirs(bp, exist_ok=True)
            try:
                with open(join(bp, "pack.mcmeta"), "w") as mcmeta:
                    json.dump(pack.meta, mcmeta, indent=4)
            except Exception as e:
                print("Build path is not valid, or folder does not exist. Error:")
                print(e)
                return

            os.makedirs(os.path.join(bp, "data"), exist_ok=True)

        else:
            print("Please set a path to compile to with scute.pack.setBuildPath()")
    else:
        print("Please set a pack name with scute.pack.setName()")
def set_build_path(path: str)

Sets the folder which your datapack will be built into - for example, "%appdata%/.minecraft/saves/world/datapacks", or "./output"

Expand source code Browse git
@staticmethod
def set_build_path(path: str):
    """
    Sets the folder which your datapack will be built into - for example, "%appdata%/.minecraft/saves/world/datapacks", or "./output"
    """
    pack.path = os.path.expandvars(path)
def set_description(desc: str)

Sets the description of your pack

Args

desc
The description
Expand source code Browse git
@staticmethod
def set_description(desc: str):
    """
    Sets the description of your pack
    Args:
        desc: The description
    """
    pack.meta["pack"]["description"] = desc
def set_main_namespace(namespace)

Sets the namespace that will be used for automatically-generated or anonymous functions

Args

namespace
The namespace
Expand source code Browse git
@staticmethod
def set_main_namespace(namespace):
    """
    Sets the namespace that will be used for automatically-generated or anonymous functions
    Args:
        namespace: The namespace
    """
    pack.namespace = namespace
def set_name(name)

Sets the display name of the pack

Args

name
The name
Expand source code Browse git
@staticmethod
def set_name(name):
    """
    Sets the display name of the pack
    Args:
        name: The name
    """
    pack.name = name
def set_version(version: str | int)

Sets the version that the pack supports

Args

version
Can be a major release like "1.19.4" (goes back to 1.16) or a pack_format number like 11
Expand source code Browse git
@staticmethod
def set_version(version: str | int):
    """
    Sets the version that the pack supports
    Args:
        version: Can be a major release like "1.19.4" (goes back to 1.16) or a pack_format number like 11
    """
    if isinstance(version, str):
        pack.meta["pack"]["pack_format"] = _versions[version]
    else:
        pack.meta["pack"]["pack_format"] = version