@@ -76,23 +76,26 @@ private void obtainModel(ResourceLocation arg, CallbackInfoReturnable<UnbakedMod
7676 ModernFix .LOGGER .info ("Baking {}" , arg );
7777 IExtendedModelBakery extendedBakery = (IExtendedModelBakery )this .field_40571 ;
7878 if (arg instanceof ModelResourceLocation && arg != ModelBakery .MISSING_MODEL_LOCATION ) {
79- /* to emulate vanilla model loading, treat as top-level */
80- Optional <Block > blockOpt = Objects .equals (((ModelResourceLocation )arg ).getVariant (), "inventory" ) ? Optional .empty () : BuiltInRegistries .BLOCK .getOptional (new ResourceLocation (arg .getNamespace (), arg .getPath ()));
81- if (blockOpt .isPresent ()) {
82- /* load via lambda for mods that expect blockstate to get loaded */
83- for (BlockState state : extendedBakery .getBlockStatesForMRL (blockOpt .get ().getStateDefinition (), (ModelResourceLocation )arg )) {
84- try {
85- blockStateLoaderHandle .invokeExact (this .field_40571 , state );
86- } catch (Throwable e ) {
87- ModernFix .LOGGER .error ("Error loading model" , e );
79+ // synchronized because we use topLevelModels
80+ synchronized (this .field_40571 ) {
81+ /* to emulate vanilla model loading, treat as top-level */
82+ Optional <Block > blockOpt = Objects .equals (((ModelResourceLocation )arg ).getVariant (), "inventory" ) ? Optional .empty () : BuiltInRegistries .BLOCK .getOptional (new ResourceLocation (arg .getNamespace (), arg .getPath ()));
83+ if (blockOpt .isPresent ()) {
84+ /* load via lambda for mods that expect blockstate to get loaded */
85+ for (BlockState state : extendedBakery .getBlockStatesForMRL (blockOpt .get ().getStateDefinition (), (ModelResourceLocation )arg )) {
86+ try {
87+ blockStateLoaderHandle .invokeExact (this .field_40571 , state );
88+ } catch (Throwable e ) {
89+ ModernFix .LOGGER .error ("Error loading model" , e );
90+ }
8891 }
92+ } else {
93+ this .field_40571 .loadTopLevel ((ModelResourceLocation )arg );
8994 }
90- } else {
91- this .field_40571 .loadTopLevel ((ModelResourceLocation )arg );
95+ cir .setReturnValue (this .field_40571 .topLevelModels .getOrDefault (arg , extendedBakery .mfix$getUnbakedMissingModel ()));
96+ // avoid leaks
97+ this .field_40571 .topLevelModels .clear ();
9298 }
93- cir .setReturnValue (this .field_40571 .topLevelModels .getOrDefault (arg , extendedBakery .mfix$getUnbakedMissingModel ()));
94- // avoid leaks
95- this .field_40571 .topLevelModels .clear ();
9699 } else
97100 cir .setReturnValue (this .field_40571 .getModel (arg ));
98101 UnbakedModel toReplace = cir .getReturnValue ();
@@ -106,14 +109,14 @@ private void obtainModel(ResourceLocation arg, CallbackInfoReturnable<UnbakedMod
106109 }
107110 }
108111 cir .setReturnValue (toReplace );
112+ cir .getReturnValue ().resolveParents (this .field_40571 ::getModel );
113+ capturedModel = cir .getReturnValue ();
109114 if (cir .getReturnValue () == extendedBakery .mfix$getUnbakedMissingModel ()) {
110115 if (arg != ModelBakery .MISSING_MODEL_LOCATION && debugDynamicModelLoading )
111116 ModernFix .LOGGER .warn ("Model {} not present" , arg );
112117 wasMissingModel = true ;
113118 } else
114119 wasMissingModel = false ; /* sometimes this runs more than once e.g. for recursive model baking */
115- cir .getReturnValue ().resolveParents (this .field_40571 ::getModel );
116- capturedModel = cir .getReturnValue ();
117120 }
118121
119122 @ 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;" ))
0 commit comments