Skip to content

Commit

Permalink
Clarify nullability of ModelModifier.AfterBake (#3212)
Browse files Browse the repository at this point in the history
* Clarify nullability of AfterBake modifier

* Fix documentation

Null baked models are cached, but only in the inner cache, which is not accessible after all baking is finished. The term "cache" is also ambiguous, so its use has been removed.

* Add breaks for v0 <0.4.0
  • Loading branch information
PepperCode1 authored and Su5eD committed Jul 27, 2023
1 parent f0545ff commit 2a0bf6d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.function.Function;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.Baker;
Expand Down Expand Up @@ -168,14 +169,19 @@ public interface AfterBake {
* This handler is invoked to allow modification of the baked model instance right after it is baked and before
* it is cached.
*
* <p>Note that the passed baked model may be null and that this handler may return a null baked model, since
* {@link UnbakedModel#bake} and {@link Baker#bake} may also return null baked models. Null baked models are
* automatically mapped to the missing model during model retrieval.
*
* <p>For further information, see the docs of {@link ModelLoadingPlugin.Context#modifyModelAfterBake()}.
*
* @param model the current baked model instance
* @param context context with additional information about the model/loader
* @return the model that should be used in this scenario. If no changes are needed, just return {@code model} as-is.
* @see ModelLoadingPlugin.Context#modifyModelAfterBake
*/
BakedModel modifyModelAfterBake(BakedModel model, Context context);
@Nullable
BakedModel modifyModelAfterBake(@Nullable BakedModel model, Context context);

/**
* The context for an after bake model modification event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ public UnbakedModel modifyModelBeforeBake(UnbakedModel model, Identifier id, Fun
return model;
}

public BakedModel modifyModelAfterBake(BakedModel model, Identifier id, UnbakedModel sourceModel, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings settings, Baker baker) {
@Nullable
public BakedModel modifyModelAfterBake(@Nullable BakedModel model, Identifier id, UnbakedModel sourceModel, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings settings, Baker baker) {
if (afterBakeModifierContextStack.isEmpty()) {
afterBakeModifierContextStack.add(new AfterBakeModifierContext());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"fabricloader": ">=0.14.21",
"fabric-api-base": "*"
},
"breaks": {
"fabric-models-v0": "<0.4.0"
},
"description": "Provides hooks for model loading.",
"mixins": [
{
Expand Down

0 comments on commit 2a0bf6d

Please sign in to comment.