11package org .embeddedt .modernfix .fabric .mixin .perf .dynamic_resources ;
22
3+ import com .llamalad7 .mixinextras .injector .wrapoperation .Operation ;
4+ import com .llamalad7 .mixinextras .injector .wrapoperation .WrapOperation ;
35import net .fabricmc .loader .api .FabricLoader ;
46import net .minecraft .client .renderer .texture .TextureAtlasSprite ;
57import net .minecraft .client .resources .model .*;
1820import org .spongepowered .asm .mixin .Shadow ;
1921import org .spongepowered .asm .mixin .injection .At ;
2022import org .spongepowered .asm .mixin .injection .Inject ;
21- import org .spongepowered .asm .mixin .injection .ModifyVariable ;
2223import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
2324
2425import java .lang .invoke .MethodHandle ;
@@ -53,22 +54,13 @@ public abstract class ModelBakerImplMixin implements IExtendedModelBaker {
5354 }
5455 }
5556
56- private ResourceLocation capturedLocation ;
57- private UnbakedModel capturedModel ;
58- private ModelState capturedState ;
59-
6057 private boolean throwIfMissing ;
6158
6259 @ Override
6360 public void throwOnMissingModel () {
6461 throwIfMissing = true ;
6562 }
6663
67- @ Inject (method = "bake" , at = @ At ("HEAD" ))
68- private void captureState (ResourceLocation rl , ModelState state , CallbackInfoReturnable <BakedModel > cir ) {
69- capturedState = state ;
70- }
71-
7264 @ Inject (method = "getModel" , at = @ At ("HEAD" ), cancellable = true )
7365 private void obtainModel (ResourceLocation arg , CallbackInfoReturnable <UnbakedModel > cir ) {
7466 if (debugDynamicModelLoading )
@@ -109,10 +101,6 @@ private void obtainModel(ResourceLocation arg, CallbackInfoReturnable<UnbakedMod
109101 }
110102 cir .setReturnValue (toReplace );
111103 cir .getReturnValue ().resolveParents (this .field_40571 ::getModel );
112- if (capturedLocation == null ) {
113- capturedLocation = arg ;
114- capturedModel = cir .getReturnValue ();
115- }
116104 if (cir .getReturnValue () == extendedBakery .mfix$getUnbakedMissingModel ()) {
117105 if (arg != ModelBakery .MISSING_MODEL_LOCATION ) {
118106 if (debugDynamicModelLoading )
@@ -123,31 +111,17 @@ private void obtainModel(ResourceLocation arg, CallbackInfoReturnable<UnbakedMod
123111 }
124112 }
125113
126- @ ModifyVariable (method = "bake" , at = @ At (value = "INVOKE_ASSIGN" , target = "Lnet/minecraft/client/resources/model/UnbakedModel;bake(Lnet/minecraft/client/resources/model/ModelBaker;Ljava/util/function/Function;Lnet/minecraft/client/resources/model/ModelState;Lnet/minecraft/resources/ResourceLocation;)Lnet/minecraft/client/resources/model/BakedModel;" ))
127- private BakedModel unifyMissingBakedModel (BakedModel model ) {
128- // Save these variables in case the nested model calls getModel somehow
129- ResourceLocation location = this .capturedLocation ;
130- UnbakedModel unbakedModel = this .capturedModel ;
131- ModelState state = this .capturedState ;
132-
133- // Safety check
134- if (location == null ) {
135- return model ;
136- }
114+ @ WrapOperation (method = "bake" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/resources/model/UnbakedModel;bake(Lnet/minecraft/client/resources/model/ModelBaker;Ljava/util/function/Function;Lnet/minecraft/client/resources/model/ModelState;Lnet/minecraft/resources/ResourceLocation;)Lnet/minecraft/client/resources/model/BakedModel;" ))
115+ private BakedModel callBakedModelIntegration (UnbakedModel unbakedModel , ModelBaker baker , Function <Material , TextureAtlasSprite > spriteGetter , ModelState state , ResourceLocation location , Operation <BakedModel > operation ) {
116+ BakedModel model = operation .call (unbakedModel , baker , spriteGetter , state , location );
137117
138118 for (ModernFixClientIntegration integration : ModernFixClient .CLIENT_INTEGRATIONS ) {
139119 model = integration .onBakedModelLoad (location , unbakedModel , model , state , this .field_40571 );
140120 }
141121
142- // Allow more capturing
143- this .capturedLocation = null ;
144- this .capturedModel = null ;
145-
146122 return model ;
147123 }
148124
149-
150-
151125 /**
152126 * @author embeddedt
153127 * @reason emulate old function, to allow injectors to work
0 commit comments