Skip to content

Commit 3add972

Browse files
committed
Merge 1.20 into 1.20.2
2 parents 6d096e8 + f4f3eff commit 3add972

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/ModelBakeryMixin.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.common.cache.Cache;
44
import com.google.common.cache.CacheBuilder;
55
import com.google.common.cache.RemovalNotification;
6+
import com.google.common.collect.ForwardingMap;
67
import com.google.common.collect.ImmutableList;
78
import net.minecraft.client.Minecraft;
89
import net.minecraft.client.color.block.BlockColors;
@@ -36,6 +37,7 @@
3637

3738
import java.io.IOException;
3839
import java.util.*;
40+
import java.util.concurrent.ConcurrentMap;
3941
import java.util.concurrent.TimeUnit;
4042
import java.util.function.BiConsumer;
4143
import java.util.function.BiFunction;
@@ -74,9 +76,14 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
7476

7577
private HashMap<ResourceLocation, UnbakedModel> smallLoadingCache = new HashMap<>();
7678

79+
// disable fabric recursion
80+
@SuppressWarnings("unused")
81+
private boolean fabric_enableGetOrLoadModelGuard;
82+
7783

7884
@Redirect(method = "<init>", at = @At(value = "FIELD", opcode = Opcodes.PUTFIELD, target = "Lnet/minecraft/client/resources/model/ModelBakery;blockColors:Lnet/minecraft/client/color/block/BlockColors;"))
7985
private void replaceTopLevelBakedModels(ModelBakery bakery, BlockColors val) {
86+
fabric_enableGetOrLoadModelGuard = false;
8087
this.blockColors = val;
8188
this.loadedBakedModels = CacheBuilder.newBuilder()
8289
.expireAfterAccess(ModelBakeryHelpers.MAX_MODEL_LIFETIME_SECS, TimeUnit.SECONDS)
@@ -93,7 +100,19 @@ private void replaceTopLevelBakedModels(ModelBakery bakery, BlockColors val) {
93100
.softValues()
94101
.build();
95102
this.bakedCache = loadedBakedModels.asMap();
96-
this.unbakedCache = loadedModels.asMap();
103+
ConcurrentMap<ResourceLocation, UnbakedModel> unbakedCacheBackingMap = loadedModels.asMap();
104+
this.unbakedCache = new ForwardingMap<ResourceLocation, UnbakedModel>() {
105+
@Override
106+
protected Map<ResourceLocation, UnbakedModel> delegate() {
107+
return unbakedCacheBackingMap;
108+
}
109+
110+
@Override
111+
public UnbakedModel put(ResourceLocation key, UnbakedModel value) {
112+
smallLoadingCache.put(key, value);
113+
return super.put(key, value);
114+
}
115+
};
97116
this.bakedTopLevelModels = new DynamicBakedModelProvider((ModelBakery)(Object)this, bakedCache);
98117
}
99118

forge/src/main/java/org/embeddedt/modernfix/platform/forge/ModernFixPlatformHooksImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public void injectPlatformSpecificHacks() {
107107
noGroupField.setAccessible(true);
108108
InjectorGroupInfo noGroup = (InjectorGroupInfo)noGroupField.get(null);
109109
groupMembersField.set(noGroup, new DummyList<>());
110+
} catch(NoSuchFieldException ignored) {
111+
// Connector will replace FML's mixin with one which already has the fix, don't bother logging
110112
} catch(RuntimeException | ReflectiveOperationException e) {
111113
ModernFixMixinPlugin.instance.logger.error("Failed to patch mixin memory leak", e);
112114
}

0 commit comments

Comments
 (0)