Skip to content

Commit 090bacb

Browse files
committed
implement NbtListParser
1 parent 921a4ac commit 090bacb

5 files changed

Lines changed: 41 additions & 10 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
3+
data_pack:
4+
load: .
5+
6+
7+
pipeline:
8+
- mecha
9+
10+
meta:
11+
mecha:
12+
multiline: true

packages/mecha/examples/list/data/test/function/test.mcfunction renamed to packages/mecha/examples/basic_list/data/test/function/test.mcfunction

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
item modify entity @s armor.feet [{function:"minecraft:set_components",components:{"minecraft:equippable":{slot:"feet",asset_id:"minecraft:netherite"}}}]
22

33

4-
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
4+
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
5+
6+
7+
8+
execute if predicate [
9+
{
10+
condition:"minecraft:value_check",
11+
name:"test:l",
12+
value:0,
13+
range:{min:0,max:2}
14+
},
15+
[
16+
{condition:"minecraft:value_check",name:"test:l",value:0,range:{min:1,max:2}}
17+
]
18+
] run say bb
19+
20+

‎packages/mecha/examples/list/beet.yaml‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎packages/mecha/src/mecha/parse.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ def get_default_parsers() -> Dict[str, Parser]:
226226
"nbt_compound_entry": nbt_parser.parse_compound_entry,
227227
"nbt_list_or_array_element": delegate("nbt"),
228228
"nbt_compound": NbtCompoundParser(delegate("nbt")),
229+
"nbt_list": NbtListParser(delegate("nbt")),
229230
"adjacent_nbt_compound": AdjacentConstraint(delegate("nbt_compound"), r"\{"),
230231
"nbt_path": NbtPathParser(
231232
integer_parser=delegate("integer"),
@@ -239,7 +240,7 @@ def get_default_parsers() -> Dict[str, Parser]:
239240
[delegate("resource_location"), delegate("nbt_compound")]
240241
),
241242
"resource_location_or_nbt_list": AlternativeParser(
242-
[delegate("resource_location_or_nbt"), delegate("nbt")]
243+
[delegate("resource_location_or_nbt"), delegate("nbt_list")]
243244
),
244245
"uuid": parse_uuid,
245246
"objective": BasicLiteralParser(AstObjective),
@@ -1325,6 +1326,15 @@ class NbtCompoundParser(TypeConstraint):
13251326
message: str = "Expected nbt compound."
13261327

13271328

1329+
@dataclass
1330+
class NbtListParser(TypeConstraint):
1331+
"""Parser for nbt compounds."""
1332+
1333+
parser: Parser = field(default_factory=NbtParser)
1334+
type: Union[Type[Any], Tuple[Type[Any], ...]] = AstNbtList
1335+
message: str = "Expected list compound."
1336+
1337+
13281338
@dataclass
13291339
class AdjacentConstraint:
13301340
"""Constraint that ensures that there are no whitespace separators."""

packages/mecha/tests/snapshots/examples__build_list__0.pack.md renamed to packages/mecha/tests/snapshots/examples__build_basic_list__0.pack.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@
2727
```mcfunction
2828
item modify entity @s armor.feet [{function: "minecraft:set_components", components: {"minecraft:equippable": {slot: "feet", asset_id: "minecraft:netherite"}}}]
2929
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
30+
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
3031
```

0 commit comments

Comments
 (0)