minecraft-datapack-language 16.0.20__py3-none-any.whl → 16.0.21__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- minecraft_datapack_language/_version.py +2 -2
- minecraft_datapack_language/mdl_compiler.py +52 -5
- {minecraft_datapack_language-16.0.20.dist-info → minecraft_datapack_language-16.0.21.dist-info}/METADATA +1 -1
- {minecraft_datapack_language-16.0.20.dist-info → minecraft_datapack_language-16.0.21.dist-info}/RECORD +8 -8
- {minecraft_datapack_language-16.0.20.dist-info → minecraft_datapack_language-16.0.21.dist-info}/WHEEL +0 -0
- {minecraft_datapack_language-16.0.20.dist-info → minecraft_datapack_language-16.0.21.dist-info}/entry_points.txt +0 -0
- {minecraft_datapack_language-16.0.20.dist-info → minecraft_datapack_language-16.0.21.dist-info}/licenses/LICENSE +0 -0
- {minecraft_datapack_language-16.0.20.dist-info → minecraft_datapack_language-16.0.21.dist-info}/top_level.txt +0 -0
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
|
|
28
28
|
commit_id: COMMIT_ID
|
29
29
|
__commit_id__: COMMIT_ID
|
30
30
|
|
31
|
-
__version__ = version = '16.0.
|
32
|
-
__version_tuple__ = version_tuple = (16, 0,
|
31
|
+
__version__ = version = '16.0.21'
|
32
|
+
__version_tuple__ = version_tuple = (16, 0, 21)
|
33
33
|
|
34
34
|
__commit_id__ = commit_id = None
|
@@ -33,6 +33,8 @@ class MDLCompiler:
|
|
33
33
|
self.declared_variables: List[VariableDeclaration] = []
|
34
34
|
# Track any temporary scoreboard variables generated during compilation
|
35
35
|
self.temp_variables: Set[str] = set()
|
36
|
+
# Track if global scope is used anywhere
|
37
|
+
self.uses_global_scope: bool = False
|
36
38
|
|
37
39
|
def compile(self, ast: Program, source_dir: str = None) -> str:
|
38
40
|
"""Compile MDL AST into a complete Minecraft datapack."""
|
@@ -174,6 +176,10 @@ class MDLCompiler:
|
|
174
176
|
lines.append(self._ensure_macro_prefix(cmd))
|
175
177
|
# Done routing temp commands for this function body
|
176
178
|
self._temp_sink_stack.pop()
|
179
|
+
|
180
|
+
# If global scope is used anywhere in the program, prepend ensure line here too
|
181
|
+
if self.uses_global_scope:
|
182
|
+
self._insert_ensure_global(lines)
|
177
183
|
|
178
184
|
return "\n".join(lines)
|
179
185
|
|
@@ -302,6 +308,11 @@ class MDLCompiler:
|
|
302
308
|
"# Generated by MDL Compiler",
|
303
309
|
""
|
304
310
|
]
|
311
|
+
|
312
|
+
# Ensure a single global armor stand exists if global scope is used
|
313
|
+
if self.uses_global_scope:
|
314
|
+
lines.extend(self._ensure_global_lines())
|
315
|
+
lines.append("")
|
305
316
|
|
306
317
|
# Add scoreboard objective creation for variables
|
307
318
|
for var_name, objective in self.variables.items():
|
@@ -774,6 +785,9 @@ class MDLCompiler:
|
|
774
785
|
else:
|
775
786
|
functions_dir = self.output_dir / "data" / self.current_namespace / "functions"
|
776
787
|
functions_dir.mkdir(parents=True, exist_ok=True)
|
788
|
+
# Insert ensure global if needed
|
789
|
+
if self.uses_global_scope:
|
790
|
+
self._insert_ensure_global(lines)
|
777
791
|
func_file = functions_dir / f"{name}.mcfunction"
|
778
792
|
with open(func_file, 'w') as f:
|
779
793
|
f.write("\n".join(lines) + "\n")
|
@@ -789,7 +803,7 @@ class MDLCompiler:
|
|
789
803
|
|
790
804
|
base = f"function {func_call.namespace}:{func_call.name}{suffix}"
|
791
805
|
if func_call.scope:
|
792
|
-
return f"execute as {func_call.scope
|
806
|
+
return f"execute as {self._resolve_scope(func_call.scope)} run {base}"
|
793
807
|
return base
|
794
808
|
|
795
809
|
def _expression_to_value(self, expression: Any) -> str:
|
@@ -807,7 +821,7 @@ class MDLCompiler:
|
|
807
821
|
return str(expression.value)
|
808
822
|
elif isinstance(expression, VariableSubstitution):
|
809
823
|
objective = self.variables.get(expression.name, expression.name)
|
810
|
-
scope = expression.scope
|
824
|
+
scope = self._resolve_scope(expression.scope)
|
811
825
|
return f"score {scope} {objective}"
|
812
826
|
elif isinstance(expression, UnaryExpression):
|
813
827
|
# Handle logical NOT elsewhere; here support unary minus for arithmetic
|
@@ -983,7 +997,7 @@ class MDLCompiler:
|
|
983
997
|
# Variable vs literal
|
984
998
|
if op_sym and isinstance(left, VariableSubstitution) and isinstance(right, LiteralExpression) and isinstance(right.value, (int, float)):
|
985
999
|
objective = self.variables.get(left.name, left.name)
|
986
|
-
scope = left.scope
|
1000
|
+
scope = self._resolve_scope(left.scope)
|
987
1001
|
# Normalize number
|
988
1002
|
try:
|
989
1003
|
v = float(right.value)
|
@@ -1025,9 +1039,9 @@ class MDLCompiler:
|
|
1025
1039
|
# Variable vs variable
|
1026
1040
|
if op_sym and isinstance(left, VariableSubstitution) and isinstance(right, VariableSubstitution):
|
1027
1041
|
lobj = self.variables.get(left.name, left.name)
|
1028
|
-
lscope = left.scope
|
1042
|
+
lscope = self._resolve_scope(left.scope)
|
1029
1043
|
robj = self.variables.get(right.name, right.name)
|
1030
|
-
rscope = right.scope
|
1044
|
+
rscope = self._resolve_scope(right.scope)
|
1031
1045
|
if op_sym in (">", ">=", "<", "<=", "=="):
|
1032
1046
|
comp = op_sym if op_sym != "==" else "="
|
1033
1047
|
return (f"score {lscope} {lobj} {comp} {rscope} {robj}", False)
|
@@ -1057,6 +1071,39 @@ class MDLCompiler:
|
|
1057
1071
|
# Fallback: treat as generic condition string
|
1058
1072
|
return (self._expression_to_condition(expression), False)
|
1059
1073
|
|
1074
|
+
def _resolve_scope(self, scope_spec: Optional[str]) -> str:
|
1075
|
+
"""Resolve MDL scope spec to a Minecraft selector string.
|
1076
|
+
- None or missing angle brackets defaults to stripping.
|
1077
|
+
- <global> maps to the singleton mdl_global armor stand.
|
1078
|
+
"""
|
1079
|
+
if not scope_spec:
|
1080
|
+
return "@s"
|
1081
|
+
s = scope_spec.strip()
|
1082
|
+
if s == "<global>":
|
1083
|
+
self.uses_global_scope = True
|
1084
|
+
return "@e[type=armor_stand,tag=mdl_global,limit=1]"
|
1085
|
+
if s.startswith("<") and s.endswith(">"):
|
1086
|
+
return s[1:-1]
|
1087
|
+
# Fallback: already looks like a selector
|
1088
|
+
return s
|
1089
|
+
|
1090
|
+
def _ensure_global_lines(self) -> list:
|
1091
|
+
return [
|
1092
|
+
"# Ensure global armor stand exists",
|
1093
|
+
"execute unless entity @e[type=armor_stand,tag=mdl_global,limit=1] run summon armor_stand ~ ~ ~ {NoGravity:1b,Invulnerable:1b,Invisible:1b,Tags:[\"mdl_global\"]}",
|
1094
|
+
]
|
1095
|
+
|
1096
|
+
def _insert_ensure_global(self, lines: list):
|
1097
|
+
# Insert ensure lines after header/comments at top if not already present
|
1098
|
+
ensure = self._ensure_global_lines()[0]
|
1099
|
+
if any(ensure in l for l in lines):
|
1100
|
+
return
|
1101
|
+
# Insert after initial comment block
|
1102
|
+
insert_at = 0
|
1103
|
+
for i, l in enumerate(lines[:5]):
|
1104
|
+
insert_at = i + 1
|
1105
|
+
lines[insert_at:insert_at] = self._ensure_global_lines() + [""]
|
1106
|
+
|
1060
1107
|
def _compile_boolean_expression(self, expression: Any, out_var: Optional[str] = None) -> str:
|
1061
1108
|
"""Compile a logical expression into a temporary boolean scoreboard variable (1 true, 0 false).
|
1062
1109
|
Returns the objective name for the boolean temp variable.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: minecraft-datapack-language
|
3
|
-
Version: 16.0.
|
3
|
+
Version: 16.0.21
|
4
4
|
Summary: Compile MDL language with explicit scoping into a Minecraft datapack (1.21+ ready). Features variables, control flow, error handling, and VS Code extension.
|
5
5
|
Project-URL: Homepage, https://www.mcmdl.com
|
6
6
|
Project-URL: Documentation, https://www.mcmdl.com/docs
|
@@ -1,18 +1,18 @@
|
|
1
1
|
minecraft_datapack_language/__init__.py,sha256=0KVXBE4ScRaRUrf83aA2tVB-y8A_jplyaxVvtHH6Uw0,1199
|
2
|
-
minecraft_datapack_language/_version.py,sha256=
|
2
|
+
minecraft_datapack_language/_version.py,sha256=XlIY3WMs9CiPI4MdJIsAr0hOM97V2wv7a_weiKPC39E,708
|
3
3
|
minecraft_datapack_language/ast_nodes.py,sha256=L5izavSeXDr766vsfRvJrcnflXNJyXcy0WSfyJPq2ZA,4484
|
4
4
|
minecraft_datapack_language/cli.py,sha256=shmQtNNXgw5XNlGquAR52wWtYeNyYusZTwwCZl56mMU,9522
|
5
5
|
minecraft_datapack_language/dir_map.py,sha256=HmxFkuvWGkzHF8o_GFb4BpuMCRc6QMw8UbmcAI8JVdY,1788
|
6
|
-
minecraft_datapack_language/mdl_compiler.py,sha256
|
6
|
+
minecraft_datapack_language/mdl_compiler.py,sha256=-nqxEbo6Pk_zo8cMDKmkIhz8vOVIRGqoESWHSgDOmD8,70118
|
7
7
|
minecraft_datapack_language/mdl_errors.py,sha256=r0Gu3KhoX1YLPAVW_iO7Q_fPgaf_Dv9tOGSOdKNSzmw,16114
|
8
8
|
minecraft_datapack_language/mdl_lexer.py,sha256=YuRflOkoMOcjECPAZzoAkJciMks5amWMtGbcTIVKmAs,24166
|
9
9
|
minecraft_datapack_language/mdl_linter.py,sha256=z85xoAglENurCh30bR7kEHZ_JeMxcYaLDcGNRAl-RAI,17253
|
10
10
|
minecraft_datapack_language/mdl_parser.py,sha256=vIcPRudxDaezNy85Q5CBcumLhCglofCNITsrRmj9YWw,27302
|
11
11
|
minecraft_datapack_language/python_api.py,sha256=Iao1jbdeW6ekeA80BZG6gNqHVjxQJEheB3DbpVsuTZQ,12304
|
12
12
|
minecraft_datapack_language/utils.py,sha256=Aq0HAGlXqj9BUTEjaEilpvzEW0EtZYYMMwOqG9db6dE,684
|
13
|
-
minecraft_datapack_language-16.0.
|
14
|
-
minecraft_datapack_language-16.0.
|
15
|
-
minecraft_datapack_language-16.0.
|
16
|
-
minecraft_datapack_language-16.0.
|
17
|
-
minecraft_datapack_language-16.0.
|
18
|
-
minecraft_datapack_language-16.0.
|
13
|
+
minecraft_datapack_language-16.0.21.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
14
|
+
minecraft_datapack_language-16.0.21.dist-info/METADATA,sha256=dW8AbMzdXeJPw755mPSuPl-7PjXkgcuCHX_QN-RKWAs,8344
|
15
|
+
minecraft_datapack_language-16.0.21.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
16
|
+
minecraft_datapack_language-16.0.21.dist-info/entry_points.txt,sha256=c6vjBeCiyQflvPHBRyBk2nJCSfYt3Oc7Sc9V87ySi_U,108
|
17
|
+
minecraft_datapack_language-16.0.21.dist-info/top_level.txt,sha256=ADtFI476tbKLLxEAA-aJQAfg53MA3k_DOb0KTFiggfw,28
|
18
|
+
minecraft_datapack_language-16.0.21.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|