Skip to content

Commit 986ae77

Browse files
committed
Fix ModeLoaderMixin conflict
Fixes #203
1 parent b307685 commit 986ae77

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package net.fabricmc.fabric.mixin.client.model.loading;
2+
3+
import net.minecraft.client.renderer.block.model.BlockModel;
4+
import net.minecraft.client.resources.model.ModelBakery;
5+
import net.minecraft.resources.ResourceLocation;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.injection.At;
8+
import org.spongepowered.asm.mixin.injection.Redirect;
9+
10+
@Mixin(value = ModelBakery.class, priority = 1)
11+
public class ModelLoaderLateMixin {
12+
// This is the call that needs to be redirected to support ModelResolvers, but it returns a JsonUnbakedModel.
13+
// Redirect it to always return null and handle the logic in a ModifyVariable right after the call.
14+
@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;"), require = 0)
15+
private BlockModel cancelLoadModelFromJson(ModelBakery self, ResourceLocation id) {
16+
return null;
17+
}
18+
}

fabric-model-loading-api-v1/src/client/java/net/fabricmc/fabric/mixin/client/model/loading/ModelLoaderMixin.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
2727
import com.llamalad7.mixinextras.sugar.Local;
2828
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet;
29+
import org.jetbrains.annotations.Nullable;
2930
import org.spongepowered.asm.mixin.Final;
3031
import org.spongepowered.asm.mixin.Mixin;
3132
import 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);

fabric-model-loading-api-v1/src/client/resources/fabric-model-loading-api-v1.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"BakedModelManagerMixin",
77
"BlockStatesLoaderMixin",
88
"ModelLoaderMixin",
9+
"ModelLoaderLateMixin",
910
"ModelLoaderBakerImplMixin"
1011
],
1112
"injectors": {

0 commit comments

Comments
 (0)