Skip to content

Commit

Permalink
feat: support inline loot arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Apr 10, 2024
1 parent 1cb0b8e commit 156b8e6
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 3 deletions.
13 changes: 10 additions & 3 deletions mecha/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ def get_default_parsers() -> Dict[str, Parser]:
"integer_range": IntegerRangeConstraint(delegate("range")),
"resource_location_or_tag": CommentDisambiguation(ResourceLocationParser()),
"resource_location": NoTagConstraint(delegate("resource_location_or_tag")),
"resource_location_or_nbt": AlternativeParser(
[delegate("resource_location"), delegate("nbt_compound")]
),
"uuid": parse_uuid,
"objective": BasicLiteralParser(AstObjective),
"objective_criteria": BasicLiteralParser(AstObjectiveCriteria),
Expand Down Expand Up @@ -488,9 +491,13 @@ def get_default_parsers() -> Dict[str, Parser]:
"command:argument:minecraft:template_mirror": delegate("template_mirror"),
"command:argument:minecraft:float_range": delegate("range"),
"command:argument:minecraft:function": delegate("resource_location_or_tag"),
"command:argument:minecraft:loot_table": delegate("resource_location"),
"command:argument:minecraft:loot_predicate": delegate("resource_location"),
"command:argument:minecraft:loot_modifier": delegate("resource_location"),
"command:argument:minecraft:loot_table": delegate("resource_location_or_nbt"),
"command:argument:minecraft:loot_predicate": delegate(
"resource_location_or_nbt"
),
"command:argument:minecraft:loot_modifier": delegate(
"resource_location_or_nbt"
),
"command:argument:minecraft:game_profile": delegate("game_profile"),
"command:argument:minecraft:gamemode": delegate("gamemode"),
"command:argument:minecraft:heightmap": delegate("heightmap"),
Expand Down
8 changes: 8 additions & 0 deletions tests/resources/argument_examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@
"examples": ["foo", "foo:bar", "#foo"]
}
],
"minecraft:loot_predicate": [
{
"examples": [
"demo:my_predicate",
"{condition:weather_check, raining:true}"
]
}
],
"minecraft:game_profile": [
{
"examples": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
minecraft:loot_predicate 0 0
---
{}
---
demo:my_predicate
---
demo:my_predicate
---
<class 'mecha.ast.AstResourceLocation'>
location: SourceLocation(pos=0, lineno=1, colno=1)
end_location: SourceLocation(pos=17, lineno=1, colno=18)
is_tag: False
namespace: 'demo'
path: 'my_predicate'
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
minecraft:loot_predicate 0 1
---
{}
---
{condition:weather_check, raining:true}
---
{condition: "weather_check", raining: 1b}
---
<class 'mecha.ast.AstNbtCompound'>
location: SourceLocation(pos=0, lineno=1, colno=1)
end_location: SourceLocation(pos=39, lineno=1, colno=40)
entries:
<class 'mecha.ast.AstNbtCompoundEntry'>
location: SourceLocation(pos=1, lineno=1, colno=2)
end_location: SourceLocation(pos=24, lineno=1, colno=25)
key:
<class 'mecha.ast.AstNbtCompoundKey'>
location: SourceLocation(pos=1, lineno=1, colno=2)
end_location: SourceLocation(pos=10, lineno=1, colno=11)
value: 'condition'
value:
<class 'mecha.ast.AstNbtValue'>
location: SourceLocation(pos=11, lineno=1, colno=12)
end_location: SourceLocation(pos=24, lineno=1, colno=25)
value: String('weather_check')
<class 'mecha.ast.AstNbtCompoundEntry'>
location: SourceLocation(pos=26, lineno=1, colno=27)
end_location: SourceLocation(pos=38, lineno=1, colno=39)
key:
<class 'mecha.ast.AstNbtCompoundKey'>
location: SourceLocation(pos=26, lineno=1, colno=27)
end_location: SourceLocation(pos=33, lineno=1, colno=34)
value: 'raining'
value:
<class 'mecha.ast.AstNbtBool'>
location: SourceLocation(pos=34, lineno=1, colno=35)
end_location: SourceLocation(pos=38, lineno=1, colno=39)
value: Byte(1)

0 comments on commit 156b8e6

Please sign in to comment.