[1.21.4] Add model loading plugins to replace ModelEvent.ModifyBakingResult
#1884
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.
This PR adds model loading plugins which are intended to replace
ModelEvent.ModifyBakingResult
. These allow more precise model wrapping, including wrapping unbaked models, and support loading custom blockstate-like formats. Another benefit of this API design is that it allows mods which implement on-demand model loading/baking a lot more control and improves compatibility between those mods and ones using the model wrapping APIs.As is probably very obvious, this PR is very heavily inspired by Fabric API's model loading APIs and therefor has an almost 100% overlap in terms of API surface and injection points.
The model loading plugins provide seven entrypoints into the model loading and baking process:
BlockStateResolver
s: blockstate resolvers are registered for specific blocks and are responsible for providing the state->model mapping for all states of the block they are registered for. This allows implementing custom blockstate-like formats, among other thingsModelEvent.ModifyBakingResult
)Apart from the missing documentation, there are still a few questions open:
BlockStateResolver
s provide access to theUnbakedBlockStateModel
s loaded by vanilla as this allows use cases where all models of a particular block have to be wrapped without having to fall back to checking every single model going through the pipeline in an on-load-block modifier.Should this access be limited to models for the states being resolved or should it be able to provide access to any model (I have a use case for this which also relies on the other block's resolver having run) which has the downside of potentially recursive resolution with on-demand loading/baking?