diff --git a/packages/mecha/examples/basic_list/beet.yaml b/packages/mecha/examples/basic_list/beet.yaml new file mode 100644 index 000000000..a9808ace3 --- /dev/null +++ b/packages/mecha/examples/basic_list/beet.yaml @@ -0,0 +1,12 @@ + + +data_pack: + load: . + + +pipeline: + - mecha + +meta: + mecha: + multiline: true diff --git a/packages/mecha/examples/basic_list/data/test/function/test.mcfunction b/packages/mecha/examples/basic_list/data/test/function/test.mcfunction new file mode 100644 index 000000000..58e96ca5e --- /dev/null +++ b/packages/mecha/examples/basic_list/data/test/function/test.mcfunction @@ -0,0 +1,20 @@ +item modify entity @s armor.feet [{function:"minecraft:set_components",components:{"minecraft:equippable":{slot:"feet",asset_id:"minecraft:netherite"}}}] + + +execute if predicate [{condition:"minecraft:all_of",terms:[{condition:"minecraft:random_chance",chance:5},{condition:"minecraft:value_check",value:0,range:0}]},{condition:"minecraft:reference",name:"test:l"}] run say aaa + + + +execute if predicate [ + { + condition:"minecraft:value_check", + name:"test:l", + value:0, + range:{min:0,max:2} + }, + [ + {condition:"minecraft:value_check",name:"test:l",value:0,range:{min:1,max:2}} + ] + ] run say bb + + diff --git a/packages/mecha/src/mecha/parse.py b/packages/mecha/src/mecha/parse.py index 953ab634b..13292fea2 100644 --- a/packages/mecha/src/mecha/parse.py +++ b/packages/mecha/src/mecha/parse.py @@ -28,6 +28,7 @@ "JsonObjectParser", "NbtParser", "NbtCompoundParser", + "NbtListParser", "AdjacentConstraint", "ResourceLocationParser", "NoTagConstraint", @@ -226,6 +227,7 @@ def get_default_parsers() -> Dict[str, Parser]: "nbt_compound_entry": nbt_parser.parse_compound_entry, "nbt_list_or_array_element": delegate("nbt"), "nbt_compound": NbtCompoundParser(delegate("nbt")), + "nbt_list": NbtListParser(delegate("nbt")), "adjacent_nbt_compound": AdjacentConstraint(delegate("nbt_compound"), r"\{"), "nbt_path": NbtPathParser( integer_parser=delegate("integer"), @@ -238,6 +240,9 @@ def get_default_parsers() -> Dict[str, Parser]: "resource_location_or_nbt": AlternativeParser( [delegate("resource_location"), delegate("nbt_compound")] ), + "resource_location_or_nbt_list": AlternativeParser( + [delegate("resource_location_or_nbt"), delegate("nbt_list")] + ), "uuid": parse_uuid, "objective": BasicLiteralParser(AstObjective), "objective_criteria": BasicLiteralParser(AstObjectiveCriteria), @@ -513,10 +518,10 @@ def get_default_parsers() -> Dict[str, Parser]: delegate("resource_location_or_nbt") ), "command:argument:minecraft:loot_predicate": MultilineParser( - delegate("resource_location_or_nbt") + delegate("resource_location_or_nbt_list") ), "command:argument:minecraft:loot_modifier": MultilineParser( - delegate("resource_location_or_nbt") + delegate("resource_location_or_nbt_list") ), "command:argument:minecraft:game_profile": delegate("game_profile"), "command:argument:minecraft:gamemode": delegate("gamemode"), @@ -1322,6 +1327,15 @@ class NbtCompoundParser(TypeConstraint): message: str = "Expected nbt compound." +@dataclass +class NbtListParser(TypeConstraint): + """Parser for nbt list.""" + + parser: Parser = field(default_factory=NbtParser) + type: Union[Type[Any], Tuple[Type[Any], ...]] = AstNbtList + message: str = "Expected nbt list." + + @dataclass class AdjacentConstraint: """Constraint that ensures that there are no whitespace separators.""" diff --git a/packages/mecha/tests/snapshots/examples__build_basic_list__0.pack.md b/packages/mecha/tests/snapshots/examples__build_basic_list__0.pack.md new file mode 100644 index 000000000..ca293a1de --- /dev/null +++ b/packages/mecha/tests/snapshots/examples__build_basic_list__0.pack.md @@ -0,0 +1,31 @@ +# Lectern snapshot + +## Data pack + +`@data_pack pack.mcmeta` + +```json +{ + "pack": { + "min_format": [ + 94, + 1 + ], + "max_format": [ + 94, + 1 + ], + "description": "" + } +} +``` + +### test + +`@function test:test` + +```mcfunction +item modify entity @s armor.feet [{function: "minecraft:set_components", components: {"minecraft:equippable": {slot: "feet", asset_id: "minecraft:netherite"}}}] +execute if predicate [{condition: "minecraft:all_of", terms: [{condition: "minecraft:random_chance", chance: 5}, {condition: "minecraft:value_check", value: 0, range: 0}]}, {condition: "minecraft:reference", name: "test:l"}] run say aaa +execute if predicate [{condition: "minecraft:value_check", name: "test:l", value: 0, range: {min: 0, max: 2}}, [{condition: "minecraft:value_check", name: "test:l", value: 0, range: {min: 1, max: 2}}]] run say bb +```