@@ -71,7 +71,6 @@ private void captureState(ResourceLocation rl, ModelState state, CallbackInfoRet
7171
7272 @ Inject (method = "getModel" , at = @ At ("HEAD" ), cancellable = true )
7373 private void obtainModel (ResourceLocation arg , CallbackInfoReturnable <UnbakedModel > cir ) {
74- capturedLocation = arg ;
7574 if (debugDynamicModelLoading )
7675 ModernFix .LOGGER .info ("Baking {}" , arg );
7776 IExtendedModelBakery extendedBakery = (IExtendedModelBakery )this .field_40571 ;
@@ -110,7 +109,10 @@ private void obtainModel(ResourceLocation arg, CallbackInfoReturnable<UnbakedMod
110109 }
111110 cir .setReturnValue (toReplace );
112111 cir .getReturnValue ().resolveParents (this .field_40571 ::getModel );
113- capturedModel = cir .getReturnValue ();
112+ if (capturedLocation == null ) {
113+ capturedLocation = arg ;
114+ capturedModel = cir .getReturnValue ();
115+ }
114116 if (cir .getReturnValue () == extendedBakery .mfix$getUnbakedMissingModel ()) {
115117 if (arg != ModelBakery .MISSING_MODEL_LOCATION ) {
116118 if (debugDynamicModelLoading )
@@ -123,9 +125,24 @@ private void obtainModel(ResourceLocation arg, CallbackInfoReturnable<UnbakedMod
123125
124126 @ 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;" ))
125127 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+ }
137+
126138 for (ModernFixClientIntegration integration : ModernFixClient .CLIENT_INTEGRATIONS ) {
127- model = integration .onBakedModelLoad (capturedLocation , capturedModel , model , capturedState , this .field_40571 );
139+ model = integration .onBakedModelLoad (location , unbakedModel , model , state , this .field_40571 );
128140 }
141+
142+ // Allow more capturing
143+ this .capturedLocation = null ;
144+ this .capturedModel = null ;
145+
129146 return model ;
130147 }
131148
0 commit comments