diff --git a/beet/contrib/dbg.py b/beet/contrib/dbg.py index 951b679aa..204f52f0a 100644 --- a/beet/contrib/dbg.py +++ b/beet/contrib/dbg.py @@ -119,7 +119,7 @@ def level_ranks(self) -> Dict[str, int]: def render_preview(self, path: str, lineno: int) -> TextComponent: """Render the preview as a text component.""" - function = self.ctx.data.functions[path] + function = self.ctx.data.function[path] lines = function.text.splitlines() preview_start = max(lineno - 1 - self.opts.preview_padding, 0) diff --git a/beet/contrib/hangman.py b/beet/contrib/hangman.py index f4668ed06..eb1b57981 100644 --- a/beet/contrib/hangman.py +++ b/beet/contrib/hangman.py @@ -59,8 +59,8 @@ def hangman(ctx: Context, opts: HangmanOptions): """Plugin that provides indentation-based syntactic extensions for functions.""" logger.warning("Deprecated in favor of mecha (https://github.com/mcbeet/mecha).") - for path in ctx.data.functions.match(*opts.match): - function = ctx.data.functions[path] + for path in ctx.data.function.match(*opts.match): + function = ctx.data.function[path] function.lines = list( fold_hanging_commands(ctx, parse_lines(function.lines), path) ) diff --git a/beet/contrib/inline_function.py b/beet/contrib/inline_function.py index a73ddb405..6351400f6 100644 --- a/beet/contrib/inline_function.py +++ b/beet/contrib/inline_function.py @@ -59,8 +59,8 @@ def _function_handler(self, path: str, op: str, caller: Any) -> str: if op == "replace": self.ctx.data[path] = function elif op == "append": - self.ctx.data.functions.setdefault(path, Function()).append(function) + self.ctx.data.function.setdefault(path, Function()).append(function) elif op == "prepend": - self.ctx.data.functions.setdefault(path, Function()).prepend(function) + self.ctx.data.function.setdefault(path, Function()).prepend(function) return "" diff --git a/beet/contrib/vanilla.py b/beet/contrib/vanilla.py index 3365266fa..90ed49af1 100644 --- a/beet/contrib/vanilla.py +++ b/beet/contrib/vanilla.py @@ -250,9 +250,9 @@ def __init__( elif opts and opts.version: self.minecraft_version = opts.version elif ctx: - self.minecraft_version = f"{ctx.minecraft_version}.*" + self.minecraft_version = ctx.minecraft_version else: - self.minecraft_version = f"{LATEST_MINECRAFT_VERSION}.*" + self.minecraft_version = LATEST_MINECRAFT_VERSION def mount( self, diff --git a/beet/library/base.py b/beet/library/base.py index 8f132f452..2897c495a 100644 --- a/beet/library/base.py +++ b/beet/library/base.py @@ -77,7 +77,7 @@ from .utils import list_extensions, list_origin_folders -LATEST_MINECRAFT_VERSION: str = "1.20" +LATEST_MINECRAFT_VERSION: str = "1.21" T = TypeVar("T") diff --git a/beet/library/data_pack.py b/beet/library/data_pack.py index a0407ea82..3fc899513 100644 --- a/beet/library/data_pack.py +++ b/beet/library/data_pack.py @@ -56,7 +56,7 @@ class Advancement(JsonFile): """Class representing an advancement.""" - scope: ClassVar[Tuple[str, ...]] = ("advancements",) + scope: ClassVar[Tuple[str, ...]] = ("advancement",) extension: ClassVar[str] = ".json" @@ -96,7 +96,7 @@ class Function(TextFileBase[List[str]]): tags: Optional[List[str]] = extra_field(default=None) prepend_tags: Optional[List[str]] = extra_field(default=None) - scope: ClassVar[Tuple[str, ...]] = ("functions",) + scope: ClassVar[Tuple[str, ...]] = ("function",) extension: ClassVar[str] = ".mcfunction" lines: ClassVar[FileDeserialize[List[str]]] = FileDeserialize() @@ -143,28 +143,28 @@ def bind(self, pack: "DataPack", path: str): class ItemModifier(JsonFile): """Class representing an item modifier.""" - scope: ClassVar[Tuple[str, ...]] = ("item_modifiers",) + scope: ClassVar[Tuple[str, ...]] = ("item_modifier",) extension: ClassVar[str] = ".json" class LootTable(JsonFile): """Class representing a loot table.""" - scope: ClassVar[Tuple[str, ...]] = ("loot_tables",) + scope: ClassVar[Tuple[str, ...]] = ("loot_table",) extension: ClassVar[str] = ".json" class Predicate(JsonFile): """Class representing a predicate.""" - scope: ClassVar[Tuple[str, ...]] = ("predicates",) + scope: ClassVar[Tuple[str, ...]] = ("predicate",) extension: ClassVar[str] = ".json" class Recipe(JsonFile): """Class representing a recipe.""" - scope: ClassVar[Tuple[str, ...]] = ("recipes",) + scope: ClassVar[Tuple[str, ...]] = ("recipe",) extension: ClassVar[str] = ".json" @@ -174,19 +174,19 @@ class Structure(BinaryFileBase[StructureFileData]): content: BinaryFileContent[StructureFileData] = None - scope: ClassVar[Tuple[str, ...]] = ("structures",) + scope: ClassVar[Tuple[str, ...]] = ("structure",) extension: ClassVar[str] = ".nbt" data: ClassVar[FileDeserialize[StructureFileData]] = FileDeserialize() def from_bytes(self, content: bytes) -> StructureFileData: with GzipFile(fileobj=io.BytesIO(content)) as fileobj: - return StructureFile.parse(fileobj).root + return StructureFile.parse(fileobj).root # type: ignore def to_bytes(self, content: StructureFileData) -> bytes: dst = io.BytesIO() with GzipFile(fileobj=dst, mode="wb") as fileobj: - StructureFile(content).write(fileobj) + StructureFile(content).write(fileobj) # type: ignore return dst.getvalue() @@ -261,37 +261,37 @@ def default(cls) -> JsonDict: class BlockTag(TagFile): """Class representing a block tag.""" - scope: ClassVar[Tuple[str, ...]] = ("tags", "blocks") + scope: ClassVar[Tuple[str, ...]] = ("tags", "block") class EntityTypeTag(TagFile): """Class representing an entity tag.""" - scope: ClassVar[Tuple[str, ...]] = ("tags", "entity_types") + scope: ClassVar[Tuple[str, ...]] = ("tags", "entity_type") class FluidTag(TagFile): """Class representing a fluid tag.""" - scope: ClassVar[Tuple[str, ...]] = ("tags", "fluids") + scope: ClassVar[Tuple[str, ...]] = ("tags", "fluid") class FunctionTag(TagFile): """Class representing a function tag.""" - scope: ClassVar[Tuple[str, ...]] = ("tags", "functions") + scope: ClassVar[Tuple[str, ...]] = ("tags", "function") class GameEventTag(TagFile): """Class representing a game event tag.""" - scope: ClassVar[Tuple[str, ...]] = ("tags", "game_events") + scope: ClassVar[Tuple[str, ...]] = ("tags", "game_event") class ItemTag(TagFile): """Class representing an item tag.""" - scope: ClassVar[Tuple[str, ...]] = ("tags", "items") + scope: ClassVar[Tuple[str, ...]] = ("tags", "item") class ChatTypeTag(TagFile): @@ -312,15 +312,15 @@ class DataPackNamespace(Namespace): directory = "data" # fmt: off - advancements: NamespacePin[Advancement] = NamespacePin(Advancement) - functions: NamespacePin[Function] = NamespacePin(Function) - item_modifiers: NamespacePin[ItemModifier] = NamespacePin(ItemModifier) - loot_tables: NamespacePin[LootTable] = NamespacePin(LootTable) - predicates: NamespacePin[Predicate] = NamespacePin(Predicate) - recipes: NamespacePin[Recipe] = NamespacePin(Recipe) + advancement: NamespacePin[Advancement] = NamespacePin(Advancement) + function: NamespacePin[Function] = NamespacePin(Function) + item_modifier: NamespacePin[ItemModifier] = NamespacePin(ItemModifier) + loot_table: NamespacePin[LootTable] = NamespacePin(LootTable) + predicate: NamespacePin[Predicate] = NamespacePin(Predicate) + recipe: NamespacePin[Recipe] = NamespacePin(Recipe) trim_pattern: NamespacePin[TrimPattern] = NamespacePin(TrimPattern) trim_material: NamespacePin[TrimMaterial] = NamespacePin(TrimMaterial) - structures: NamespacePin[Structure] = NamespacePin(Structure) + structure: NamespacePin[Structure] = NamespacePin(Structure) chat_type: NamespacePin[ChatType] = NamespacePin(ChatType) damage_type: NamespacePin[DamageType] = NamespacePin(DamageType) banner_patterns: NamespacePin[BannerPattern] = NamespacePin(BannerPattern) @@ -350,19 +350,20 @@ class DataPack(Pack[DataPackNamespace]): (1, 18): 9, (1, 19): 12, (1, 20): 41, + (1, 21): 48, } latest_pack_format = pack_format_registry[split_version(LATEST_MINECRAFT_VERSION)] # fmt: off - advancements: NamespaceProxyDescriptor[Advancement] = NamespaceProxyDescriptor(Advancement) - functions: NamespaceProxyDescriptor[Function] = NamespaceProxyDescriptor(Function) - item_modifiers: NamespaceProxyDescriptor[ItemModifier] = NamespaceProxyDescriptor(ItemModifier) - loot_tables: NamespaceProxyDescriptor[LootTable] = NamespaceProxyDescriptor(LootTable) - predicates: NamespaceProxyDescriptor[Predicate] = NamespaceProxyDescriptor(Predicate) - recipes: NamespaceProxyDescriptor[Recipe] = NamespaceProxyDescriptor(Recipe) + advancement: NamespaceProxyDescriptor[Advancement] = NamespaceProxyDescriptor(Advancement) + function: NamespaceProxyDescriptor[Function] = NamespaceProxyDescriptor(Function) + item_modifier: NamespaceProxyDescriptor[ItemModifier] = NamespaceProxyDescriptor(ItemModifier) + loot_table: NamespaceProxyDescriptor[LootTable] = NamespaceProxyDescriptor(LootTable) + predicate: NamespaceProxyDescriptor[Predicate] = NamespaceProxyDescriptor(Predicate) + recipe: NamespaceProxyDescriptor[Recipe] = NamespaceProxyDescriptor(Recipe) trim_pattern: NamespaceProxyDescriptor[TrimPattern] = NamespaceProxyDescriptor(TrimPattern) trim_material: NamespaceProxyDescriptor[TrimMaterial] = NamespaceProxyDescriptor(TrimMaterial) - structures: NamespaceProxyDescriptor[Structure] = NamespaceProxyDescriptor(Structure) + structure: NamespaceProxyDescriptor[Structure] = NamespaceProxyDescriptor(Structure) chat_type: NamespaceProxyDescriptor[ChatType] = NamespaceProxyDescriptor(ChatType) damage_type: NamespaceProxyDescriptor[DamageType] = NamespaceProxyDescriptor(DamageType) banner_patterns: NamespaceProxyDescriptor[BannerPattern] = NamespaceProxyDescriptor(BannerPattern) diff --git a/beet/library/resource_pack.py b/beet/library/resource_pack.py index e191cbda6..68a824fed 100644 --- a/beet/library/resource_pack.py +++ b/beet/library/resource_pack.py @@ -340,6 +340,7 @@ class ResourcePack(Pack[ResourcePackNamespace]): (1, 18): 8, (1, 19): 13, (1, 20): 32, + (1, 21): 34, } latest_pack_format = pack_format_registry[split_version(LATEST_MINECRAFT_VERSION)] diff --git a/docs/overview.md b/docs/overview.md index da4cf1a22..13720996b 100644 --- a/docs/overview.md +++ b/docs/overview.md @@ -62,14 +62,14 @@ pack == { Namespace containers are also available through attribute access. This is usually the syntax you'll be looking for as it's a bit more readable and provides better autocompletion. ```{code-cell} -demo_namespace.functions["foo"] is demo_namespace[Function]["foo"] +demo_namespace.function["foo"] is demo_namespace[Function]["foo"] ``` You can even omit the container entirely when adding files to the namespace. The namespace will dispatch the file to the appropriate container automatically depending on its type. ```{code-cell} demo_namespace["bar"] = Function(["say world"]) -demo_namespace.functions +demo_namespace.function ``` ### Resource locations @@ -81,15 +81,15 @@ Data pack objects let you access files in a single lookup with proxies that expo ```{code-cell} pack = DataPack() -pack.functions["demo:foo"] = Function() -pack.functions["demo:foo"] is pack["demo"].functions["foo"] +pack.function["demo:foo"] = Function() +pack.function["demo:foo"] is pack["demo"].function["foo"] ``` Proxy attributes are always in sync with the underlying namespaces. You can also omit the attribute when adding files to data packs. The data pack object will dispatch the file to the appropriate proxy depending on its type. ```{code-cell} pack["demo:bar"] = Function() -pack.functions == { +pack.function == { "demo:foo": Function(), "demo:bar": Function(), } @@ -272,17 +272,17 @@ pack.match("d*") ``` ```{code-cell} -pack["demo"].functions.match("f*") +pack["demo"].function.match("f*") ``` ```{code-cell} -pack.functions.match("demo:*") +pack.function.match("demo:*") ``` You can specify multiple patterns. The exclamation mark lets you invert a pattern. ```{code-cell} -pack.functions.match("demo:*", "!demo:foo") +pack.function.match("demo:*", "!demo:foo") ``` ## File handles @@ -420,14 +420,14 @@ The files used in data packs and resource packs are derived from the core file h ```{code-cell} pack = DataPack(path="../examples/load_basic/src") -pack.functions["demo:foo"] +pack.function["demo:foo"] ``` As you can see, when we load an unzipped data pack all the files remain in their unloaded state. The moment we start interacting with the content of the function `beet` will load the file automatically. ```{code-cell} -pack.functions["demo:foo"].lines.append("say bar") -pack.functions["demo:foo"] +pack.function["demo:foo"].lines.append("say bar") +pack.function["demo:foo"] ``` ## The toolchain @@ -457,11 +457,11 @@ out └── greeting_data_pack ├── data │ ├── greeting - │ │ └── functions + │ │ └── function │ │ └── hello.mcfunction │ └── minecraft │ └── tags - │ └── functions + │ └── function │ └── load.json └── pack.mcmeta @@ -518,11 +518,11 @@ out └── greeting_data_pack ├── data │ ├── greeting - │ │ └── functions + │ │ └── function │ │ └── hello.mcfunction │ └── minecraft │ └── tags - │ └── functions + │ └── function │ └── load.json └── pack.mcmeta @@ -558,11 +558,11 @@ out ├── greeting_data_pack │ ├── data │ │ ├── greeting -│ │ │ └── functions +│ │ │ └── function │ │ │ └── hello.mcfunction │ │ └── minecraft │ │ └── tags -│ │ └── functions +│ │ └── function │ │ └── load.json │ └── pack.mcmeta └── greeting_resource_pack diff --git a/examples/code_draft/demo.py b/examples/code_draft/demo.py index 6e404d300..4402f1c64 100644 --- a/examples/code_draft/demo.py +++ b/examples/code_draft/demo.py @@ -11,4 +11,4 @@ def beet_default(ctx: Context): draft.cache("demo", f"{message=}", zipped=True) draft.data["demo:message"] = Function([f"say {message}"]) - ctx.data.functions["demo:message"].lines *= 2 + ctx.data.function["demo:message"].lines *= 2 diff --git a/examples/code_mount/demo.py b/examples/code_mount/demo.py index 415531adf..618a059b9 100644 --- a/examples/code_mount/demo.py +++ b/examples/code_mount/demo.py @@ -2,8 +2,8 @@ def beet_default(ctx: Context): - ctx.data.mount("data/demo/functions", ctx.directory / "src") - ctx.data.mount("data/owo/functions/foo.mcfunction", ctx.directory / "src/thing.txt") + ctx.data.mount("data/demo/function", ctx.directory / "src") + ctx.data.mount("data/owo/function/foo.mcfunction", ctx.directory / "src/thing.txt") ctx.data.mount("pack.mcmeta", ctx.directory / "pack.mcmeta") ctx.assets.mount("assets/minecraft", ctx.directory / "src") ctx.assets.mount("assets/other/sounds.json", ctx.directory / "src/sounds.json") diff --git a/examples/code_mount_load/demo.py b/examples/code_mount_load/demo.py index cd4cd6f64..72404739c 100644 --- a/examples/code_mount_load/demo.py +++ b/examples/code_mount_load/demo.py @@ -6,8 +6,8 @@ def beet_default(ctx: Context): ctx.require( load( data_pack={ - "data/demo/functions": ctx.directory / "src", - "data/owo/functions/foo.mcfunction": ctx.directory / "src/thing.txt", + "data/demo/function": ctx.directory / "src", + "data/owo/function/foo.mcfunction": ctx.directory / "src/thing.txt", "pack.mcmeta": ctx.directory / "pack.mcmeta", }, resource_pack={ diff --git a/examples/code_sandbox/demo.py b/examples/code_sandbox/demo.py index 6ed33aefa..061a1761a 100644 --- a/examples/code_sandbox/demo.py +++ b/examples/code_sandbox/demo.py @@ -11,7 +11,7 @@ def beet_default(ctx: Context): def add_function(name: str): def plugin(ctx: Context): - function_count = len(ctx.data.functions) + function_count = len(ctx.data.function) last_function = ctx.meta.get("last_function") ctx.data[name] = Function([f"say {function_count=} {last_function=}"]) ctx.meta["last_function"] = name diff --git a/examples/code_worker/demo.py b/examples/code_worker/demo.py index 7bb35ac99..e56fc4589 100644 --- a/examples/code_worker/demo.py +++ b/examples/code_worker/demo.py @@ -20,7 +20,7 @@ def other(ctx: Context): yield - ctx.data["demo:function_count"] = Function([f"say {len(ctx.data.functions)}"]) + ctx.data["demo:function_count"] = Function([f"say {len(ctx.data.function)}"]) for name, function in channel: ctx.data[name] = function diff --git a/examples/load_broadcast_extend/libs/bar/beet.yml b/examples/load_broadcast_extend/libs/bar/beet.yml index ffd107879..96523e80b 100644 --- a/examples/load_broadcast_extend/libs/bar/beet.yml +++ b/examples/load_broadcast_extend/libs/bar/beet.yml @@ -1,3 +1,3 @@ data_pack: load: - data/bar/functions: "src" + data/bar/function: "src" diff --git a/examples/load_broadcast_extend/libs/foo/beet.yml b/examples/load_broadcast_extend/libs/foo/beet.yml index e5a640b23..b9c76c26c 100644 --- a/examples/load_broadcast_extend/libs/foo/beet.yml +++ b/examples/load_broadcast_extend/libs/foo/beet.yml @@ -1,3 +1,3 @@ data_pack: load: - data/foo/functions: "src" + data/foo/function: "src" diff --git a/examples/load_extend/demo.py b/examples/load_extend/demo.py index 41be59f26..02495032f 100644 --- a/examples/load_extend/demo.py +++ b/examples/load_extend/demo.py @@ -33,7 +33,7 @@ def extend_data_pack(ctx: Context): def process_functions(ctx: Context): project_data = cast(JsonFile, ctx.data.extra["myproject.json"]).data - for prefix, dirs, functions in ctx.data.functions.walk(): + for prefix, dirs, functions in ctx.data.function.walk(): dirs.discard("zprivate") namespace = ctx.data[prefix.partition(":")[0]] diff --git a/examples/load_find_replace/beet.yml b/examples/load_find_replace/beet.yml index 76959ba9b..3cb61d265 100644 --- a/examples/load_find_replace/beet.yml +++ b/examples/load_find_replace/beet.yml @@ -1,7 +1,7 @@ pipeline: - data_pack: load: - data/demo/functions/thing1.mcfunction: "thing1.mcfunction" + data/demo/function/thing1.mcfunction: "thing1.mcfunction" pipeline: - beet.contrib.find_replace meta: diff --git a/examples/load_mount/beet.yml b/examples/load_mount/beet.yml index cf1c3d35f..14d667621 100644 --- a/examples/load_mount/beet.yml +++ b/examples/load_mount/beet.yml @@ -1,7 +1,7 @@ data_pack: load: - data/demo/functions: "src" - data/owo/functions/foo.mcfunction: "src/thing.txt" + data/demo/function: "src" + data/owo/function/foo.mcfunction: "src/thing.txt" pack.mcmeta: "pack.mcmeta" resource_pack: load: diff --git a/examples/load_mount_functions/beet.yml b/examples/load_mount_functions/beet.yml index 62a16f07b..45af1002e 100644 --- a/examples/load_mount_functions/beet.yml +++ b/examples/load_mount_functions/beet.yml @@ -1,8 +1,8 @@ data_pack: load: # mount all .mcfunction files in "src" - data/demo/functions: "src" + data/demo/function: "src" # put gcd.mcfunction and is_prime.mcfunction in "math_util" - data/demo/functions/math_util: ["vendor/gcd.mcfunction", "vendor/is_prime.mcfunction"] + data/demo/function/math_util: ["vendor/gcd.mcfunction", "vendor/is_prime.mcfunction"] # add schedule_clock.mcfunction as main.mcfunction - data/demo/functions/main.mcfunction: "vendor/schedule_clock.mcfunction" + data/demo/function/main.mcfunction: "vendor/schedule_clock.mcfunction" diff --git a/examples/load_mount_glob/beet.yml b/examples/load_mount_glob/beet.yml index 441c49e4a..9711170a8 100644 --- a/examples/load_mount_glob/beet.yml +++ b/examples/load_mount_glob/beet.yml @@ -1,4 +1,4 @@ data_pack: load: - data/demo/functions: + data/demo/function: - "src/*.mcfunction" diff --git a/examples/load_mount_zip/beet.yml b/examples/load_mount_zip/beet.yml index 4e20cf297..dfb7ed355 100644 --- a/examples/load_mount_zip/beet.yml +++ b/examples/load_mount_zip/beet.yml @@ -1,6 +1,6 @@ data_pack: load: - data/demo/functions: "src.zip" + data/demo/function: "src.zip" resource_pack: load: assets/minecraft: "src.zip" diff --git a/examples/load_rename_files/beet.yml b/examples/load_rename_files/beet.yml index e222ab44a..5e93bc3e2 100644 --- a/examples/load_rename_files/beet.yml +++ b/examples/load_rename_files/beet.yml @@ -2,7 +2,7 @@ pipeline: - name: Demo data_pack: load: - data/demo/functions/foo1.mcfunction: "foo1.mcfunction" + data/demo/function/foo1.mcfunction: "foo1.mcfunction" pipeline: - beet.contrib.rename_files meta: diff --git a/examples/nosnap_load_http/beet.yml b/examples/nosnap_load_http/beet.yml index e8afea2c2..6528752ac 100644 --- a/examples/nosnap_load_http/beet.yml +++ b/examples/nosnap_load_http/beet.yml @@ -1,6 +1,6 @@ data_pack: load: - "https://raw.githubusercontent.com/Gamemode4Dev/GM4_Datapacks/release/1.20/gm4_double_doors_1_20.zip" - - data/demo/functions/foo.mcfunction: "https://gist.githubusercontent.com/vberlier/acee1bf5193fc885141dab652fa3bad5/raw/0c338576e32554fffdab9d7f483147bb3234aac1/foo.mcfunction" + - data/demo/function/foo.mcfunction: "https://gist.githubusercontent.com/vberlier/acee1bf5193fc885141dab652fa3bad5/raw/0c338576e32554fffdab9d7f483147bb3234aac1/foo.mcfunction" zipped: false output: "out" diff --git a/examples/nosnap_vanilla/beet.yml b/examples/nosnap_vanilla/beet.yml index 002ff618b..51a9c1b94 100644 --- a/examples/nosnap_vanilla/beet.yml +++ b/examples/nosnap_vanilla/beet.yml @@ -8,8 +8,8 @@ meta: assets/foo/lang/en_us.json: assets/minecraft/lang/en_us.json assets/minecraft/lang: - assets/minecraft/lang/fr.* - data/foo/recipes: - - data/minecraft/recipes/.*bee.* + data/foo/recipe: + - data/minecraft/recipe/.*bee.* assets/foo/models/\1: assets/minecraft/models/(block|item)/.+_sapling.json assets/foo/textures/map: assets/minecraft/textures/map match: diff --git a/examples/nosnap_vanilla/demo.py b/examples/nosnap_vanilla/demo.py index 42ac6c309..a4ce5bb48 100644 --- a/examples/nosnap_vanilla/demo.py +++ b/examples/nosnap_vanilla/demo.py @@ -7,11 +7,11 @@ def beet_default(ctx: Context): assert vanilla.releases["22w11a"].type == "snapshot" - ctx.data.loot_tables.merge( - vanilla.mount("data/minecraft/loot_tables").data.loot_tables + ctx.data.loot_table.merge( + vanilla.mount("data/minecraft/loot_table").data.loot_table ) - ctx.data["demo"].recipes.merge( - vanilla.mount("data/minecraft/recipes").data["minecraft"].recipes + ctx.data["demo"].recipe.merge( + vanilla.mount("data/minecraft/recipe").data["minecraft"].recipe ) client_jar = vanilla.mount("assets/minecraft/lang") diff --git a/tests/test_data_pack.py b/tests/test_data_pack.py index 4213ed9fe..d28049e7b 100644 --- a/tests/test_data_pack.py +++ b/tests/test_data_pack.py @@ -63,15 +63,15 @@ def test_namespaces(): assert p1 == p2 assert p1["hello"] == p2["hello"] - p2.functions["hello:world"].lines.append("say world") + p2.function["hello:world"].lines.append("say world") - assert p1.functions["hello:world"] != p2.functions["hello:world"] + assert p1.function["hello:world"] != p2.function["hello:world"] assert p1["hello"] != p2["hello"] assert p1 != p2 - p1["hello"].functions["world"].lines.append("say world") # type: ignore + p1["hello"].function["world"].lines.append("say world") # type: ignore - assert p1.functions["hello:world"] == p2.functions["hello:world"] + assert p1.function["hello:world"] == p2.function["hello:world"] assert p1["hello"] == p2["hello"] assert p1 == p2 @@ -115,7 +115,7 @@ def test_context_manager(tmp_path: Path): p2 = DataPack(path=tmp_path / "foobar") assert p2 == p1 - assert p2.functions["hello:world"].lines == ["say hello"] + assert p2.function["hello:world"].lines == ["say hello"] assert p2.function_tags["minecraft:load"].data == {"values": ["hello:world"]} assert p2 == p1 @@ -135,14 +135,14 @@ def test_context_manager_zipped(tmp_path: Path): p2 = DataPack(path=tmp_path / "foobar.zip") - assert p2.functions["hello:world"].lines == ["say hello"] + assert p2.function["hello:world"].lines == ["say hello"] assert p2.function_tags["minecraft:load"].data == {"values": ["hello:world"]} assert p2 == p1 - p1.functions["hello:world"].lines.append("say world") + p1.function["hello:world"].lines.append("say world") assert p2 != p1 - p2["hello"].functions["world"].lines.append("say world") + p2["hello"].function["world"].lines.append("say world") assert p2 == p1 @@ -163,7 +163,7 @@ def test_vanilla_content(minecraft_data_pack: Path): def test_vanilla_igloo(minecraft_data_pack: Path): pack = DataPack(path=minecraft_data_pack) - assert pack.structures["minecraft:igloo/top"].data["size"] == [7, 5, 8] + assert pack.structure["minecraft:igloo/top"].data["size"] == [7, 5, 8] def test_vanilla_igloo_content(minecraft_data_pack: Path): @@ -199,7 +199,7 @@ def test_merge_tags(): p1.merge(p2) - assert len(p1.functions) == 2 + assert len(p1.function) == 2 assert len(p1.function_tags) == 1 assert p1.function_tags["minecraft:tick"].data == { "values": ["hello:func1", "hello:func2"] @@ -250,26 +250,26 @@ def test_match(): funcs = [f"path/to/func_{i:02d}" for i in range(100)] - assert custom.functions.match() == set() + assert custom.function.match() == set() - assert custom.functions.match("*") == set(funcs) | { + assert custom.function.match("*") == set(funcs) | { "path/to/end", "other/subdir/hello", "other/subdir/world", "other/thing", } - assert custom.functions.match("path/to/func_0*") == set(funcs[:10]) - assert custom.functions.match("path/to/func_*") == set(funcs) + assert custom.function.match("path/to/func_0*") == set(funcs[:10]) + assert custom.function.match("path/to/func_*") == set(funcs) - assert custom.functions.match("path/to") == set(funcs) | {"path/to/end"} - assert custom.functions.match("path/to/func_*", "other") == set(funcs) | { + assert custom.function.match("path/to") == set(funcs) | {"path/to/end"} + assert custom.function.match("path/to/func_*", "other") == set(funcs) | { "other/subdir/hello", "other/subdir/world", "other/thing", } - assert custom.functions.match("other/subdir") == { + assert custom.function.match("other/subdir") == { "other/subdir/hello", "other/subdir/world", } @@ -295,9 +295,9 @@ def test_proxy_match(): custom_funcs = [f"custom:path/to/func_{i:02d}" for i in range(100)] hey_funcs = [f"hey:path/to/func_{i:02d}" for i in range(100)] - assert pack.functions.match() == set() + assert pack.function.match() == set() - assert pack.functions.match("*") == set(custom_funcs) | set(hey_funcs) | { + assert pack.function.match("*") == set(custom_funcs) | set(hey_funcs) | { "custom:path/to/end", "custom:other/subdir/hello", "custom:other/subdir/world", @@ -305,20 +305,20 @@ def test_proxy_match(): "hey:other/subdir/hello", } - assert pack.functions.match("custom:*") == set(custom_funcs) | { + assert pack.function.match("custom:*") == set(custom_funcs) | { "custom:path/to/end", "custom:other/subdir/hello", "custom:other/subdir/world", "custom:other/thing", } - assert pack.functions.match("*:other/subdir") == { + assert pack.function.match("*:other/subdir") == { "custom:other/subdir/hello", "custom:other/subdir/world", "hey:other/subdir/hello", } - assert pack.functions.match( + assert pack.function.match( "*:path/to/func_0*", "*:path/to/end", "hey:other" ) == set(custom_funcs[:10]) | set(hey_funcs[:10]) | { "custom:path/to/end", @@ -329,7 +329,7 @@ def test_proxy_match(): def test_overload_proxy(): pack = DataPack() pack["demo:foo"] = Function(["say foo"]) - assert pack[Function]["demo:foo"] is pack.functions["demo:foo"] + assert pack[Function]["demo:foo"] is pack.function["demo:foo"] def test_accessors_with_function(tmp_path: Path): @@ -369,7 +369,7 @@ def on_bind_callback(instance: Function, pack: DataPack, path: str): ["say hello"], tags=["minecraft:load"], on_bind=on_bind_callback ) - assert pack.functions == { + assert pack.function == { "hello:world": Function(["say hello"]), "hello:world_alias": Function(["function hello:world"]), } @@ -442,7 +442,7 @@ def nuke(*args: Any) -> bool: p1.merge(p2) assert p1.description == "" - assert list(p1.functions) == ["demo:bar"] + assert list(p1.function) == ["demo:bar"] assert list(p1["demo"].extra) == [] assert p1["thing"].extra["foo.json"] == JsonFile() @@ -481,16 +481,16 @@ def test_query(): query = PackQuery([p]) selection = { - (k := "data/demo/functions/foo.mcfunction", p.functions["demo:foo"]): (p, k), - (k := "data/demo/functions/bar.mcfunction", p.functions["demo:bar"]): (p, k), + (k := "data/demo/function/foo.mcfunction", p.function["demo:foo"]): (p, k), + (k := "data/demo/function/bar.mcfunction", p.function["demo:bar"]): (p, k), } assert query(".mcfunction", files=r".*") == selection assert query(extend=Function, files=r".*") == selection selection = { Function: { - (k := "demo:foo", p.functions["demo:foo"]): (p, k), - (k := "demo:bar", p.functions["demo:bar"]): (p, k), + (k := "demo:foo", p.function["demo:foo"]): (p, k), + (k := "demo:bar", p.function["demo:bar"]): (p, k), } } assert query(".mcfunction", match="*") == selection @@ -508,33 +508,33 @@ def test_query(): assert query(extend=Mcmeta, match="*") == {} assert set(query.distinct(files=r".*\.json")) == { - p.loot_tables["demo:some_loot"], - p.loot_tables["demo:some_other_loot"], - p.loot_tables["minecraft:default_loot"], + p.loot_table["demo:some_loot"], + p.loot_table["demo:some_other_loot"], + p.loot_table["minecraft:default_loot"], p.function_tags["minecraft:tick"], p.function_tags["minecraft:load"], p.block_tags["other_namespace:what/is/that"], } assert set(query.distinct(files=r"data/minecraft/.*\.json")) == { - p.loot_tables["minecraft:default_loot"], + p.loot_table["minecraft:default_loot"], p.function_tags["minecraft:tick"], p.function_tags["minecraft:load"], } assert set(query.distinct(".json", match=r"minecraft:*")) == { - p.loot_tables["minecraft:default_loot"], + p.loot_table["minecraft:default_loot"], p.function_tags["minecraft:tick"], p.function_tags["minecraft:load"], } assert set(query.distinct(extend=JsonFileBase[Any], match=r"minecraft:*")) == { - p.loot_tables["minecraft:default_loot"], + p.loot_table["minecraft:default_loot"], p.function_tags["minecraft:tick"], p.function_tags["minecraft:load"], } assert set(query.distinct(extend=JsonFileBase[Any], files=r".*")) == { p.mcmeta, - p.loot_tables["demo:some_loot"], - p.loot_tables["demo:some_other_loot"], - p.loot_tables["minecraft:default_loot"], + p.loot_table["demo:some_loot"], + p.loot_table["demo:some_other_loot"], + p.loot_table["minecraft:default_loot"], p.function_tags["minecraft:tick"], p.function_tags["minecraft:load"], p.block_tags["other_namespace:what/is/that"], @@ -542,20 +542,20 @@ def test_query(): assert set(query.distinct(files=[r".*loot\.json", r"pack\.mcmeta"])) == { p.mcmeta, - p.loot_tables["demo:some_loot"], - p.loot_tables["demo:some_other_loot"], - p.loot_tables["minecraft:default_loot"], + p.loot_table["demo:some_loot"], + p.loot_table["demo:some_other_loot"], + p.loot_table["minecraft:default_loot"], } assert set(query.distinct(files={"regex": r".*LoOt.*", "flags": "IGNORECASE"})) == { - p.loot_tables["demo:some_loot"], - p.loot_tables["demo:some_other_loot"], - p.loot_tables["minecraft:default_loot"], + p.loot_table["demo:some_loot"], + p.loot_table["demo:some_other_loot"], + p.loot_table["minecraft:default_loot"], } assert set(query.distinct(match=["minecraft:*", "demo:*", "!*other*"])) == { - p.functions["demo:foo"], - p.functions["demo:bar"], - p.loot_tables["demo:some_loot"], - p.loot_tables["minecraft:default_loot"], + p.function["demo:foo"], + p.function["demo:bar"], + p.loot_table["demo:some_loot"], + p.loot_table["minecraft:default_loot"], p.function_tags["minecraft:tick"], p.function_tags["minecraft:load"], } @@ -570,8 +570,8 @@ def test_query_rename(): assert query(match={"function": {"demo:nested": ["demo:foo", "demo:bar"]}}) == { Function: { - ("demo:nested/foo", p.functions["demo:foo"]): (p, "demo:foo"), - ("demo:nested/bar", p.functions["demo:bar"]): (p, "demo:bar"), + ("demo:nested/foo", p.function["demo:foo"]): (p, "demo:foo"), + ("demo:nested/bar", p.function["demo:bar"]): (p, "demo:bar"), } } @@ -597,7 +597,7 @@ def test_query_copy(): FunctionTag: {"my_foo": FunctionTag({"values": ["demo:foo"]})}, } } - assert p.functions["demo:foo"] == target1.functions["stuff:foo"] + assert p.function["demo:foo"] == target1.function["stuff:foo"] assert p.function_tags["demo:my_foo"] == target1.function_tags["stuff:my_foo"] @@ -666,8 +666,8 @@ def test_overlay(): assert c.overlay_name == "c" assert c.overlay_parent is p assert dict(p.list_files()) == { - "a/data/demo/functions/foo.mcfunction": Function(["say hello"]), - "c/data/demo/functions/thing.mcfunction": Function([]), + "a/data/demo/function/foo.mcfunction": Function(["say hello"]), + "c/data/demo/function/thing.mcfunction": Function([]), "pack.mcmeta": Mcmeta( { "pack": {"pack_format": DataPack.latest_pack_format, "description": ""}, @@ -713,7 +713,7 @@ def test_overlay(): p.merge(q) assert p.overlays["stuff"].overlay_parent is p - assert p.overlays["stuff"].functions["demo:stuff"] == Function(["say stuff"]) + assert p.overlays["stuff"].function["demo:stuff"] == Function(["say stuff"]) assert p.overlays["stuff"].supported_formats is None assert p.overlays["bingo"].overlays is p.overlays @@ -727,29 +727,29 @@ def test_overlay(): assert p.overlays["d"].overlays is p.overlays assert p.overlays["bop"].overlays is p.overlays assert p.overlays["bop2"].overlays is p.overlays - assert p.overlays["d"].functions["demo:init"] == Function(["say original init"]) - assert p.overlays["bop"].functions["demo:init"] == Function(["say init"]) - assert p.overlays["bop2"].functions["demo:init"] == Function() + assert p.overlays["d"].function["demo:init"] == Function(["say original init"]) + assert p.overlays["bop"].function["demo:init"] == Function(["say init"]) + assert p.overlays["bop2"].function["demo:init"] == Function() select = PackQuery([p]) assert select(match={"function": "*"}) == { Function: { - (k := "demo:foo", a.functions["demo:foo"]): (a, k), - (k := "demo:init", d.functions["demo:init"]): (d, k), - (k := "demo:init", p.overlays["bop"].functions["demo:init"]): ( + (k := "demo:foo", a.function["demo:foo"]): (a, k), + (k := "demo:init", d.function["demo:init"]): (d, k), + (k := "demo:init", p.overlays["bop"].function["demo:init"]): ( p.overlays["bop"], k, ), - (k := "demo:init", p.overlays["bop2"].functions["demo:init"]): ( + (k := "demo:init", p.overlays["bop2"].function["demo:init"]): ( p.overlays["bop2"], k, ), - (k := "demo:stuff", p.overlays["stuff"].functions["demo:stuff"]): ( + (k := "demo:stuff", p.overlays["stuff"].function["demo:stuff"]): ( p.overlays["stuff"], k, ), - (k := "demo:thing", c.functions["demo:thing"]): (c, k), + (k := "demo:thing", c.function["demo:thing"]): (c, k), } } @@ -813,34 +813,34 @@ def test_copy(): assert p_copy == p assert p_copy.extra["thing.txt"] is not p.extra["thing.txt"] assert ( - p_copy.overlays["a"].functions["demo:foo"] - is not p.overlays["a"].functions["demo:foo"] + p_copy.overlays["a"].function["demo:foo"] + is not p.overlays["a"].function["demo:foo"] ) - assert p_copy.functions["demo:foo"] is not p.functions["demo:foo"] + assert p_copy.function["demo:foo"] is not p.function["demo:foo"] assert p_copy["demo"].extra["dank.txt"] is not p["demo"].extra["dank.txt"] p.clear() assert not p assert p_copy.extra["thing.txt"] == TextFile("wow") - assert p_copy.overlays["a"].functions["demo:foo"] == Function(["say 1"]) - assert p_copy.functions["demo:foo"] == Function(["say 2"]) + assert p_copy.overlays["a"].function["demo:foo"] == Function(["say 1"]) + assert p_copy.function["demo:foo"] == Function(["say 2"]) assert p_copy["demo"].extra["dank.txt"] == TextFile("ok") p_shallow = p_copy.copy(shallow=True) assert p_shallow == p_copy assert p_shallow.extra["thing.txt"] is p_copy.extra["thing.txt"] assert ( - p_shallow.overlays["a"].functions["demo:foo"] - is p_copy.overlays["a"].functions["demo:foo"] + p_shallow.overlays["a"].function["demo:foo"] + is p_copy.overlays["a"].function["demo:foo"] ) - assert p_shallow.functions["demo:foo"] is p_copy.functions["demo:foo"] + assert p_shallow.function["demo:foo"] is p_copy.function["demo:foo"] assert p_shallow["demo"].extra["dank.txt"] is p_copy["demo"].extra["dank.txt"] p_copy.clear() assert not p_copy assert p_shallow.extra["thing.txt"] == TextFile("wow") - assert p_shallow.overlays["a"].functions["demo:foo"] == Function(["say 1"]) - assert p_shallow.functions["demo:foo"] == Function(["say 2"]) + assert p_shallow.overlays["a"].function["demo:foo"] == Function(["say 1"]) + assert p_shallow.function["demo:foo"] == Function(["say 2"]) assert p_shallow["demo"].extra["dank.txt"] == TextFile("ok")