diff --git a/bolt/runtime.py b/bolt/runtime.py index 219aa4b..ca03643 100644 --- a/bolt/runtime.py +++ b/bolt/runtime.py @@ -182,7 +182,9 @@ def from_module_import(self, resource_location: str, *args: str) -> Any: def get_nested_location(self) -> str: """Return the resource location associated with the current level of nesting.""" root, relative_path = NestedLocationResolver.concat_nested_path( - self.walk_location_hierarchy() + NestedLocationResolver.walk_location_hierarchy( + self.spec, reversed(self.nesting) + ) ) if not root: @@ -195,21 +197,6 @@ def get_nested_location(self) -> str: ) return f"{namespace}:{resolved}" - def walk_location_hierarchy(self) -> Iterator[AstResourceLocation]: - """Yield resource locations contributing to the current nested context.""" - for identifier, arguments in reversed(self.nesting): - prototype = self.spec.prototypes[identifier] - - for i, argument_node in enumerate(arguments): - node = self.spec.tree.get(prototype.get_argument(i).scope) - if ( - node - and node.parser == "minecraft:function" - and isinstance(argument_node, AstResourceLocation) - ): - yield argument_node - break - def finalize(self, ctx: Context): """Plugin that runs at the end of the build.""" try: diff --git a/examples/bolt_nested_location/src/data/ref/functions/foo.mcfunction b/examples/bolt_nested_location/src/data/ref/functions/foo.mcfunction new file mode 100644 index 0000000..a2ad313 --- /dev/null +++ b/examples/bolt_nested_location/src/data/ref/functions/foo.mcfunction @@ -0,0 +1,39 @@ +x = "" + +function ~/{x} +function ~/thing{x} +function ~/../thing{x} + +function ref:bar: + function ~/{x} + function ~/thing{x} + function ~/../thing{x} + + append function ~/thing{x}: + function #~/aaa{x} + +function ./wat: + function ~/{x} + function ~/thing{x} + function ~/../thing{x} + + append function ~/thing{x}: + function #~/bbb{x} + +function ~/this{x}: + function ~/{x} + function ~/thing{x} + function ~/../thing{x} + + append function ~/thing{x}: + function #~/ccc{x} + +function ~/../upthis{x}: + function ~/{x} + function ~/thing{x} + function ~/../thing{x} + + append function ~/thing{x}: + function #~/ddd{x} + +execute if function ~/condition{x} run function ~/action{x} diff --git a/poetry.lock b/poetry.lock index a2c111a..8a0e1c4 100644 --- a/poetry.lock +++ b/poetry.lock @@ -714,14 +714,14 @@ files = [ [[package]] name = "mecha" -version = "0.86.0" +version = "0.86.5" description = "A powerful Minecraft command library" category = "main" optional = false python-versions = ">=3.10,<4.0" files = [ - {file = "mecha-0.86.0-py3-none-any.whl", hash = "sha256:75f8b1f6bd3a197c379bfbb96b3018585cc7d39134f9054861b232eefd8c4eef"}, - {file = "mecha-0.86.0.tar.gz", hash = "sha256:69177b1f46ada51f31830adf42f6fc743505d4ff494b774718016c58460468c6"}, + {file = "mecha-0.86.5-py3-none-any.whl", hash = "sha256:9e7bda76d5882c7202addae84600db4f1fd537d34730d7c5d4140a1b0eb70a4a"}, + {file = "mecha-0.86.5.tar.gz", hash = "sha256:070878948f678f88d63194fadb9600b4df562e26a1433f67b1827f4cec9c397b"}, ] [package.dependencies] @@ -1581,4 +1581,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "51bd7a524a33410ea80a59619fd50bfad30a9a2f3b21cbb73e156bb680d01801" +content-hash = "84cedb2f8ea26149e38a25c300823e73461610b4c8b7fec0aef681c430f3a6d6" diff --git a/pyproject.toml b/pyproject.toml index 5b516c0..0753f0a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,7 @@ include = ["bolt/py.typed"] [tool.poetry.dependencies] python = "^3.10" beet = ">=0.100.0" -mecha = ">=0.86.0" +mecha = ">=0.86.5" [tool.poetry.group.dev.dependencies] pytest = "^7.4.3" diff --git a/tests/snapshots/examples__build_bolt_nested_location__0.pack.md b/tests/snapshots/examples__build_bolt_nested_location__0.pack.md index cd35f21..8b51757 100644 --- a/tests/snapshots/examples__build_bolt_nested_location__0.pack.md +++ b/tests/snapshots/examples__build_bolt_nested_location__0.pack.md @@ -48,3 +48,70 @@ schedule function demo:foo/thing1/blob 2s append ```mcfunction execute if predicate demo:welp run say yes ``` + +### ref + +`@function ref:foo` + +```mcfunction +function ref:foo +function ref:foo/thing +function ref:thing +execute if function ref:foo/condition run function ref:foo/action +``` + +`@function ref:bar/thing` + +```mcfunction +function #ref:bar/thing/aaa +``` + +`@function ref:wat/thing` + +```mcfunction +function #ref:wat/thing/bbb +``` + +`@function ref:foo/this/thing` + +```mcfunction +function #ref:foo/this/thing/ccc +``` + +`@function ref:upthis/thing` + +```mcfunction +function #ref:upthis/thing/ddd +``` + +`@function ref:bar` + +```mcfunction +function ref:bar +function ref:bar/thing +function ref:thing +``` + +`@function ref:wat` + +```mcfunction +function ref:wat +function ref:wat/thing +function ref:thing +``` + +`@function ref:foo/this` + +```mcfunction +function ref:foo/this +function ref:foo/this/thing +function ref:foo/thing +``` + +`@function ref:upthis` + +```mcfunction +function ref:upthis +function ref:upthis/thing +function ref:thing +```