Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Model Loading API to 1.21.4 #4243

Merged
merged 7 commits into from
Nov 30, 2024

Conversation

PepperCode1
Copy link
Member

@PepperCode1 PepperCode1 commented Nov 22, 2024

  • Split model modifier events and callbacks - one set for static models and one set for block models
    • This is necessary because static models use UnbakedModel and are baked with settings while block models use GroupableModel and are not baked with settings
    • This cleans up the Identifier/ModelIdentifier getters
    • This allows providing the BlockState directly to ModelModifier.OnLoadBlock
  • Remove before and after bake events
    • BeforeBake and AfterBake can be perfectly replicated with OnLoad since it is now possible to replace any UnbakedModel with any other UnbakedModel (not just JsonUnbakedModel) in 1.21.4
    • BeforeBakeBlock and AfterBakeBlock can be perfectly replicated with OnLoadBlock and GroupableModel no longer extends UnbakedModel
    • These events were given a Baker, but ran after model discovery was done, so using the baker could be unreliable
    • BeforeBakeBlock and AfterBakeBlock run after the creation of block model groups is done, so replacing the block model using these events would not update the block model groups
  • ModelModifier.OnLoad can now accept a null model, which is a model that was requested during resolution but does not have a corresponding JSON file; Remove ModelResolver as its functionality can now be perfectly replicated with ModelModifier.OnLoad with OVERRIDE_PHASE
  • Remove sprite getter from callback contexts as it is now accessible directly through the Baker
  • Adjust Nullable annotations to match vanilla changes
  • Add UnwrappableBakedModel
    • Moved and renamed from FRAPI's WrapperBakedModel (original will be deleted in Port FRAPI to 1.21.4 and refactor #4247)
    • Implement it and interface inject it on vanilla's WrapperBakedModel
    • Add new static UnwrappableBakedModel#unwrap method which accepts a Predicate saying when to stop unwrapping
  • Add WrapperUnbakedModel which simply delegates all method calls to a different UnbakedModel
  • Add WrapperGroupableModel which simply delegates all method calls to a different GroupableModel
  • Remove DelegatingUnbakedModel as GroupableModel no longer extends UnbakedModel, so BlockModelResolvers can no longer use it, which was its original purpose; it is also not suitable for use in ModelModifier.OnLoad as returning one would affect all child models, which is usually not the desired behavior
  • Remove BuiltinItemRenderer, BuiltinItemRendererRegistry, and BuiltinItemRendererRegistryImpl (part of Rendering v1, not Model Loading API v1) as they were replaced by a TAW to SpecialModelTypes.ID_MAPPER

- Split model modifier events and callbacks - one set for static models and one set for block models
  - This is necessary because static models use UnbakedModel and are baked with settings while block models use GroupableModel and are not baked with settings
  - This cleans up the Identifier/ModelIdentifier getters
  - OnLoad for block models was not added because the unbaked block model map is not a cache and block models cannot inherit from other models
- Make DelegatingUnbakedModel a record to allow accessing the delegate ID
- Remove BuiltinItemRenderer, BuiltinItemRendererRegistry, and BuiltinItemRendererRegistryImpl as they were replaced by a TAW to SpecialModelTypes.ID_MAPPER
@modmuss50 modmuss50 added the port Porting existing code to a different version label Nov 22, 2024
- The functionality of ModelResolver could be perfectly replicated with ModelModifier.OnLoad with OVERRIDE_PHASE
- The functionality of BlockStateResolver could be perfectly replicated with ModelModifier.BeforeBakeBlock with OVERRIDE_PHASE
- Fix log warning caused by half_red_sand.json not defining particle sprite
@PepperCode1 PepperCode1 marked this pull request as draft November 23, 2024 16:41
- BeforeBakeBlock runs too late to allow modifying how models are grouped, so OnLoadBlock is necessary to allow that
- OnLoadBlock only runs for models which were actually loaded from blockstate files, so BlockStateResolver is necessary to allow adding models for blocks without a corresponding blockstate file
- Add UnwrappableBakedModel
  - Moved and renamed from FRAPI's WrapperBakedModel (original will be deleted in separate PR)
  - Implement it and interface inject it on vanilla's WrapperBakedModel
  - Add new static UnwrappableBakedModel#unwrap method which accepts a Predicate saying when to stop unwrapping
- Add WrapperUnbakedModel which simply delegates all method calls to a different UnbakedModel
@PepperCode1 PepperCode1 added the priority:high High priority PRs that need review and work now. Review these first. label Nov 27, 2024
- Remove BeforeBake, AfterBake, BeforeBakeBlock, AfterBakeBlock
- Remove DelegatingUnbakedModel
- Add WrapperGroupableModel
- Add documentation and extra constructor to WrapperUnbakedModel
@PepperCode1 PepperCode1 marked this pull request as ready for review November 30, 2024 17:42
@modmuss50 modmuss50 added the last call If you care, make yourself heard right away! label Nov 30, 2024
@modmuss50 modmuss50 merged commit 6a293bd into FabricMC:1.21.4 Nov 30, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
last call If you care, make yourself heard right away! port Porting existing code to a different version priority:high High priority PRs that need review and work now. Review these first.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants