11package org .embeddedt .modernfix .fabric .mixin .perf .dynamic_resources ;
22
3+ import com .google .common .collect .ImmutableList ;
34import com .llamalad7 .mixinextras .injector .wrapoperation .Operation ;
45import com .llamalad7 .mixinextras .injector .wrapoperation .WrapOperation ;
56import net .fabricmc .loader .api .FabricLoader ;
@@ -75,9 +76,19 @@ private void obtainModel(ResourceLocation arg, CallbackInfoReturnable<UnbakedMod
7576 synchronized (this .field_40571 ) {
7677 /* to emulate vanilla model loading, treat as top-level */
7778 Optional <Block > blockOpt = Objects .equals (((ModelResourceLocation )arg ).getVariant (), "inventory" ) ? Optional .empty () : BuiltInRegistries .BLOCK .getOptional (new ResourceLocation (arg .getNamespace (), arg .getPath ()));
79+ boolean invalidMRL = false ;
7880 if (blockOpt .isPresent ()) {
7981 /* load via lambda for mods that expect blockstate to get loaded */
80- for (BlockState state : extendedBakery .getBlockStatesForMRL (blockOpt .get ().getStateDefinition (), (ModelResourceLocation )arg )) {
82+ ImmutableList <BlockState > states ;
83+ try {
84+ states = extendedBakery .getBlockStatesForMRL (blockOpt .get ().getStateDefinition (), (ModelResourceLocation )arg );
85+ } catch (RuntimeException e ) {
86+ states = ImmutableList .of ();
87+ invalidMRL = true ;
88+ // Fall back to getModel
89+ cir .setReturnValue (this .field_40571 .getModel (arg ));
90+ }
91+ for (BlockState state : states ) {
8192 try {
8293 blockStateLoaderHandle .invokeExact (this .field_40571 , state );
8394 } catch (Throwable e ) {
@@ -87,9 +98,11 @@ private void obtainModel(ResourceLocation arg, CallbackInfoReturnable<UnbakedMod
8798 } else {
8899 this .field_40571 .loadTopLevel ((ModelResourceLocation )arg );
89100 }
90- cir .setReturnValue (this .field_40571 .topLevelModels .getOrDefault (arg , extendedBakery .mfix$getUnbakedMissingModel ()));
91- // avoid leaks
92- this .field_40571 .topLevelModels .clear ();
101+ if (!invalidMRL ) {
102+ cir .setReturnValue (this .field_40571 .topLevelModels .getOrDefault (arg , extendedBakery .mfix$getUnbakedMissingModel ()));
103+ // avoid leaks
104+ this .field_40571 .topLevelModels .clear ();
105+ }
93106 }
94107 } else
95108 cir .setReturnValue (this .field_40571 .getModel (arg ));
0 commit comments