Add support for default components #232
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
data_components.pycodegen now additionally writes toazalea-inventory/src/default_components/generated.rswithDefaultableComponentimpls for every component that has default implementations for any items, by translating Mojang'sitems.jsonto Rust values.It's optimized to generate different impls based on some heuristics, so for some components it'll use a lookup table and for others it'll write a match statement. I don't expect that the codegen will need to be changed for most updates, except for when Mojang adds another more unusual looking components.
Note that this approach has the downside of making it more complicated to get a list of default components for an item (because you'd have to call
default_for_itemfor everyDefaultableComponent), but I don't expect this to be a common case (since usually you only care about a single component at a time).