2626import com .llamalad7 .mixinextras .injector .wrapoperation .WrapOperation ;
2727import com .llamalad7 .mixinextras .sugar .Local ;
2828import it .unimi .dsi .fastutil .objects .ObjectLinkedOpenHashSet ;
29+ import org .jetbrains .annotations .Nullable ;
2930import org .spongepowered .asm .mixin .Final ;
3031import org .spongepowered .asm .mixin .Mixin ;
3132import org .spongepowered .asm .mixin .Shadow ;
@@ -119,7 +120,7 @@ private void allowRecursiveLoading(ResourceLocation id, CallbackInfoReturnable<U
119120 } else if (modelLoadingStack .contains (id )) {
120121 throw new IllegalStateException ("Circular reference while loading model '" + id + "' (" + modelLoadingStack .stream ().map (i -> i + "->" ).collect (Collectors .joining ()) + id + ")" );
121122 } else {
122- UnbakedModel model = loadModel (id );
123+ UnbakedModel model = loadModel (id , null );
123124 unbakedCache .put (id , model );
124125 // These will be loaded at the top-level call.
125126 loadingStack .addAll (model .getDependencies ());
@@ -128,27 +129,24 @@ private void allowRecursiveLoading(ResourceLocation id, CallbackInfoReturnable<U
128129 }
129130 }
130131
131- // This is the call that needs to be redirected to support ModelResolvers, but it returns a JsonUnbakedModel.
132- // Redirect it to always return null and handle the logic in a ModifyVariable right after the call.
133- @ Redirect (method = "getModel" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/resources/model/ModelBakery;loadBlockModel(Lnet/minecraft/resources/ResourceLocation;)Lnet/minecraft/client/renderer/block/model/BlockModel;" ))
134- private BlockModel cancelLoadModelFromJson (ModelBakery self , ResourceLocation id ) {
135- return null ;
136- }
137-
138132 @ ModifyVariable (method = "getModel" , at = @ At (value = "INVOKE_ASSIGN" , target = "Lnet/minecraft/client/resources/model/ModelBakery;loadBlockModel(Lnet/minecraft/resources/ResourceLocation;)Lnet/minecraft/client/renderer/block/model/BlockModel;" ))
139133 private UnbakedModel doLoadModel (UnbakedModel model , @ Local (ordinal = 1 ) ResourceLocation id ) {
140- return loadModel (id );
134+ return loadModel (id , model );
141135 }
142136
143137 @ Unique
144- private UnbakedModel loadModel (ResourceLocation id ) {
138+ private UnbakedModel loadModel (ResourceLocation id , @ Nullable UnbakedModel oldModel ) {
145139 modelLoadingStack .add (id );
146140
147141 try {
148142 UnbakedModel model = fabric_eventDispatcher .resolveModel (id );
149143
150144 if (model == null ) {
151- model = loadBlockModel (id );
145+ if (oldModel == null ) {
146+ model = loadBlockModel (id );
147+ } else {
148+ model = oldModel ;
149+ }
152150 }
153151
154152 return fabric_eventDispatcher .modifyModelOnLoad (model , id , null );
0 commit comments