diff --git a/src/jmc/compile/command/builtin_function/execute_excluded.py b/src/jmc/compile/command/builtin_function/execute_excluded.py index 2f4449f9..0e9ad491 100644 --- a/src/jmc/compile/command/builtin_function/execute_excluded.py +++ b/src/jmc/compile/command/builtin_function/execute_excluded.py @@ -22,7 +22,7 @@ def _hardcode_parse(calc_pos: int, string: str, token: Token, elif char == ")": count -= 1 - if char not in {"0", "1", "2", "3", "4", "5", "6", "7", + if char not in {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "-", "*", "/", "\\", "%", " ", "\t", "\n", "(", ")"}: raise JMCSyntaxException( @@ -36,7 +36,8 @@ def _hardcode_parse(calc_pos: int, string: str, token: Token, raise JMCSyntaxException( "Invalid syntax in Hardcode.calc", token, tokenizer, display_col_length=False) - return string[:calc_pos] + eval_expr(expression.replace("\\", "//")) + string[index + 13:] + return string[:calc_pos] + \ + eval_expr(expression.replace("\\", "//")) + string[index + 13:] def _hardcode_process(string: str, index_string: str, diff --git a/src/jmc/compile/command/builtin_function/load_only.py b/src/jmc/compile/command/builtin_function/load_only.py index ec3296e4..1f2cac39 100644 --- a/src/jmc/compile/command/builtin_function/load_only.py +++ b/src/jmc/compile/command/builtin_function/load_only.py @@ -270,7 +270,7 @@ def call(self) -> str: ) class ItemCreateSign(JMCFunction): _VARIANTS = {"oak", "spruce", "birch", "jungle", - "acacia", "dark_oak", "crimson", "warped", + "acacia", "dark_oak", "crimson", "warped", "mangrove", "bamboo", "cherry"} def call(self) -> str: @@ -1210,7 +1210,7 @@ def inner(arg: str) -> SIMPLE_JSON_BODY: self.add_formatted_text_prop( "clickEvent", inner, self.check_bool("local")) return "" - + @func_property( func_type=FuncType.LOAD_ONLY, @@ -1233,12 +1233,12 @@ def call(self) -> str: "Unexpected empty URL", self.raw_args["url"].token, self.tokenizer) - + self.add_formatted_text_prop( "clickEvent", { "action": "open_url", "value": self.args["url"]}, self.check_bool("local")) return "" - + @func_property( func_type=FuncType.LOAD_ONLY, @@ -1262,7 +1262,7 @@ def call(self) -> str: "Unexpected empty URL", self.raw_args["url"].token, self.tokenizer) - + @lru_cache() def inner(arg: str) -> SIMPLE_JSON_BODY: return { @@ -1296,12 +1296,12 @@ def call(self) -> str: "Unexpected empty page number", self.raw_args["page"].token, self.tokenizer) - + self.add_formatted_text_prop( "clickEvent", { "action": "change_page", "value": self.args["page"]}, self.check_bool("local")) return "" - + @func_property( func_type=FuncType.LOAD_ONLY, @@ -1317,7 +1317,7 @@ def call(self) -> str: ) class TextPropsClickPage(JMCFunction): def call(self) -> str: - + @lru_cache() def inner(arg: str) -> SIMPLE_JSON_BODY: return { @@ -1325,7 +1325,7 @@ def inner(arg: str) -> SIMPLE_JSON_BODY: self.add_formatted_text_prop( "clickEvent", inner, self.check_bool("local")) return "" - + @func_property( func_type=FuncType.LOAD_ONLY, @@ -1348,12 +1348,12 @@ def call(self) -> str: "Unexpected empty clipboard content", self.raw_args["text"].token, self.tokenizer) - + self.add_formatted_text_prop( "clickEvent", { "action": "copy_to_clipboard", "value": self.args["text"]}, self.check_bool("local")) return "" - + @func_property( func_type=FuncType.LOAD_ONLY, @@ -1377,7 +1377,7 @@ def call(self) -> str: "Unexpected emptyclipboard content", self.raw_args["text"].token, self.tokenizer) - + @lru_cache() def inner(arg: str) -> SIMPLE_JSON_BODY: return { @@ -1385,7 +1385,7 @@ def inner(arg: str) -> SIMPLE_JSON_BODY: self.add_formatted_text_prop( "clickEvent", inner, self.check_bool("local")) return "" - + @func_property( func_type=FuncType.LOAD_ONLY, @@ -1408,7 +1408,7 @@ def call(self) -> str: "Unexpected empty FormattedText", self.raw_args["text"].token, self.tokenizer) - + self.add_formatted_text_prop( "hoverEvent", { "action": "show_text", "contents": json.loads(self.format_text("text"))}, self.check_bool("local")) @@ -1437,7 +1437,7 @@ def call(self) -> str: "Unexpected empty FormattedText", self.raw_args["text"].token, self.tokenizer) - + @lru_cache() def inner(arg: str) -> SIMPLE_JSON_BODY: return { @@ -1445,7 +1445,7 @@ def inner(arg: str) -> SIMPLE_JSON_BODY: self.add_formatted_text_prop( "hoverEvent", inner, self.check_bool("local")) return "" - + @func_property( func_type=FuncType.LOAD_ONLY, @@ -1468,7 +1468,7 @@ def call(self) -> str: "Missing item in TextProp.hoverItem", self.raw_args["item"].token, self.tokenizer) - + self.add_formatted_text_prop( "hoverEvent", { "action": "show_item", "contents": json.loads(self.args["item"])}, self.check_bool("local")) @@ -1497,7 +1497,7 @@ def call(self) -> str: "Missing item in TextProps.hoverItem", self.raw_args["item"].token, self.tokenizer) - + @lru_cache() def inner(arg: str) -> SIMPLE_JSON_BODY: return { @@ -1528,7 +1528,7 @@ def call(self) -> str: "Missing entity in TextProp.hoverEntity", self.raw_args["entity"].token, self.tokenizer) - + self.add_formatted_text_prop( "hoverEvent", { "action": "show_entity", "contents": json.loads(self.args["entity"])}, self.check_bool("local")) @@ -1557,7 +1557,7 @@ def call(self) -> str: "Missing entity in TextProps.hoverEntity", self.raw_args["entity"].token, self.tokenizer) - + @lru_cache() def inner(arg: str) -> SIMPLE_JSON_BODY: return { @@ -1588,7 +1588,7 @@ def call(self) -> str: "Missing font in TextProp.font", self.raw_args["font"].token, self.tokenizer) - + self.add_formatted_text_prop( "font", self.args["font"], self.check_bool("local")) return "" @@ -1616,14 +1616,14 @@ def call(self) -> str: "Missing font in TextProps.font", self.raw_args["font"].token, self.tokenizer) - + @lru_cache() def inner(arg: str) -> SIMPLE_JSON_BODY: return self.args["font"].replace(self.args["indexString"], arg) self.add_formatted_text_prop( "font", inner, self.check_bool("local")) return "" - + @func_property( func_type=FuncType.LOAD_ONLY, @@ -1682,7 +1682,7 @@ def inner(arg: str) -> SIMPLE_JSON_BODY: "keybind", inner, self.check_bool("local")) return "" - + @func_property( func_type=FuncType.LOAD_ONLY, call_string="TextProp.nbt", @@ -1722,7 +1722,7 @@ def call(self) -> str: self.tokenizer) self.add_formatted_text_prop( - "__private_nbt_expand__", {self.args["type"]: self.args["source"], "nbt": self.args["path"], "interpret": self.args["interpret"]}, self.check_bool("local")) + "__private_nbt_expand__", {self.args["type"]: self.args["source"], "nbt": self.args["path"], "interpret": self.args["interpret"]}, self.check_bool("local")) return "" @@ -1767,9 +1767,10 @@ def call(self) -> str: @lru_cache() def inner(arg: str) -> SIMPLE_JSON_BODY: - return {self.args["type"]: self.args["source"], "nbt": self.args["path"].replace(self.args["indexString"], arg), "interpret": self.args["interpret"]} + return {self.args["type"]: self.args["source"], "nbt": self.args["path"].replace( + self.args["indexString"], arg), "interpret": self.args["interpret"]} self.add_formatted_text_prop( - "__private_nbt_expand__", inner, self.check_bool("local")) + "__private_nbt_expand__", inner, self.check_bool("local")) return "" diff --git a/src/jmc/compile/command/utils.py b/src/jmc/compile/command/utils.py index ec968042..b65aa995 100644 --- a/src/jmc/compile/command/utils.py +++ b/src/jmc/compile/command/utils.py @@ -371,7 +371,7 @@ def eval_expr(expr: str) -> str: OPERATORS: dict[type, Callable[..., Any]] = {ast.Add: op.add, ast.Sub: op.sub, ast.Mult: op.mul, - ast.Div: op.truediv, ast.FloorDiv: op.floordiv, ast.Mod: op.mod, + ast.Div: op.truediv, ast.FloorDiv: op.floordiv, ast.Mod: op.mod, ast.Pow: op.pow, ast.USub: op.neg} @@ -599,14 +599,14 @@ def __parse_bracket(self) -> None: key, json_body, is_local = self.datapack.data.formatted_text_prop[prop_] if isinstance(json_body, dict) and 'nbt' in json_body.keys(): self.current_json[key] = {} - self.current_json[key]["nbt"] = json_body["nbt"](arg) # type: ignore - self.current_json[key]["interpret"] = json_body["interpret"](arg) # type: ignore + self.current_json[key]["nbt"] = json_body["nbt"](arg) # type: ignore # fmt: off + self.current_json[key]["interpret"] = json_body["interpret"](arg) # type: ignore # fmt: off if "entity" in json_body.keys(): - self.current_json[key]["entity"] = json_body["entity"] # type: ignore + self.current_json[key]["entity"] = json_body["entity"] # type: ignore # fmt: off if "block" in json_body.keys(): - self.current_json[key]["block"] = json_body["block"] # type: ignore + self.current_json[key]["block"] = json_body["block"] # type: ignore # fmt: off if "storage" in json_body.keys(): - self.current_json[key]["storage"] = json_body["storage"] # type: ignore + self.current_json[key]["storage"] = json_body["storage"] # type: ignore # fmt: off elif not callable(json_body): raise JMCValueError( f"Custom property '{prop_}' expected no argument", self.token, self.tokenizer, suggestion="Remove '()'") @@ -644,24 +644,24 @@ def __parse_bracket(self) -> None: del self.current_json["text"] if "__private_nbt_expand__" in self.current_json: - self.current_json["nbt"] = self.current_json["__private_nbt_expand__"]["nbt"] # type: ignore - self.current_json["interpret"] = self.current_json["__private_nbt_expand__"]["interpret"] # type: ignore - if "storage" in self.current_json["__private_nbt_expand__"]: # type: ignore - self.current_json["storage"] = self.current_json["__private_nbt_expand__"]["storage"] # type: ignore - if "block" in self.current_json["__private_nbt_expand__"]: # type: ignore - self.current_json["block"] = self.current_json["__private_nbt_expand__"]["block"] # type: ignore - if "entity" in self.current_json["__private_nbt_expand__"]: # type: ignore - self.current_json["entity"] = self.current_json["__private_nbt_expand__"]["entity"] # type: ignore + self.current_json["nbt"] = self.current_json["__private_nbt_expand__"]["nbt"] # type: ignore # fmt: off + self.current_json["interpret"] = self.current_json["__private_nbt_expand__"]["interpret"] # type: ignore # fmt: off + if "storage" in self.current_json["__private_nbt_expand__"]: # type: ignore # fmt: off + self.current_json["storage"] = self.current_json["__private_nbt_expand__"]["storage"] # type: ignore # fmt: off + if "block" in self.current_json["__private_nbt_expand__"]: # type: ignore # fmt: off + self.current_json["block"] = self.current_json["__private_nbt_expand__"]["block"] # type: ignore # fmt: off + if "entity" in self.current_json["__private_nbt_expand__"]: # type: ignore # fmt: off + self.current_json["entity"] = self.current_json["__private_nbt_expand__"]["entity"] # type: ignore # fmt: off del self.current_json["__private_nbt_expand__"] tmp_json: SIMPLE_JSON_TYPE = {"text": ""} for prop_, value_ in self.current_json.items(): - if prop_ in {"bold", "italic", "underlined", + if prop_ in {"bold", "italic", "underlined", "strikethrough", "obfuscated", "color"}: tmp_json[prop_] = value_ self.result.append(self.current_json) self.current_json = tmp_json - + def __parse_code(self, char: str) -> None: """ Parse color code diff --git a/src/jmc/compile/compiling.py b/src/jmc/compile/compiling.py index 1e75b04a..20c91405 100644 --- a/src/jmc/compile/compiling.py +++ b/src/jmc/compile/compiling.py @@ -324,8 +324,8 @@ def build(datapack: DataPack, config: "Configuration", is_delete: bool, cert_con for func_path, func in datapack.functions.items(): namespace = func_path.split("/")[0] if namespace in header.namespace_overrides: - path = output_folder / "data" / namespace / "functions" / \ - (func_path[len(namespace)+1:] + ".mcfunction") + path = output_folder / "data" / namespace / "functions" / \ + (func_path[len(namespace) + 1:] + ".mcfunction") else: path = namespace_folder / "functions" / (func_path + ".mcfunction") content = post_process(func.content) @@ -341,7 +341,7 @@ def build(datapack: DataPack, config: "Configuration", is_delete: bool, cert_con namespace = json_path.split("/")[0] if namespace in header.namespace_overrides: path = output_folder / "data" / \ - namespace / (json_path[len(namespace)+1:] + ".json") + namespace / (json_path[len(namespace) + 1:] + ".json") else: path = namespace_folder / (json_path + ".json") if json: diff --git a/src/jmc/compile/lexer.py b/src/jmc/compile/lexer.py index a024425f..78a9b279 100644 --- a/src/jmc/compile/lexer.py +++ b/src/jmc/compile/lexer.py @@ -361,7 +361,8 @@ def parse_new(self, tokenizer: Tokenizer, namespace = json_name.split("/")[0] if namespace in Header().namespace_overrides: - json_path = namespace + "/" + json_type + "/" + json_name[len(namespace)+1:] + json_path = namespace + "/" + json_type + \ + "/" + json_name[len(namespace) + 1:] else: json_path = json_type + "/" + json_name