Open SPGoding opened 11 months ago
Expected behavior (without imp-doc):
// mod.mcdoc
dispatch minecraft:storage[example:foo] to struct {
one: string,
two: byte,
}
// foo.mcfunction
data merge storage example:foo {one:"hello",two:1b}
function example:macro with storage example:foo
^^^^^^^^^^^^^^^^^^^^^^^^
Missing key "three"
function example:macro {one:"hello",three:"world"}
^
Missing key "two"
// macro.mcfunction
# (translates to `struct {one: any, two: any, three: any}`)
$say hello $(one) $(two) $(three)
Expected behavior via an external implicit dispatch in mcdoc:
// example_library/mcdoc/mod.mcdoc
dispatch minecraft:function[example_library:macro] to struct {
one: string,
two: byte,
}
// example_library/data/example_library/function/macro.mcfunction
$say hello $(one) $(two)
$say wrong $(three)
^^^^^
Unknown macro argument key "three"
// mcdoc/mod.mcdoc
dispatch minecraft:storage[example:foo] to minecraft:function[example_library:macro]
// data/example/foo.mcfunction
data merge storage example:foo {one:"hello",two:1b, three: 3.3f}
^^^^^
Unknown key "three"
data merge storage example:foo {one:"hello",two:1b}
function example_library:macro with storage example:foo
function example_library:macro {one:"hello",two:"world"}
^^^^^^^
Expected a byte, got a string
The IMP Doc successor will have more options for this, but will be a separate issue
We should not attempt to parse function macros as commands. Still, some validation can be done to ensure all macro parameters are provided.
An mcdoc struct should be automatically constructed based on macro parameters used in a function. When calling such functions, we should validate that the provided data value is assignable to the generated mcdoc struct.