33import com .google .common .cache .Cache ;
44import com .google .common .cache .CacheBuilder ;
55import com .google .common .cache .RemovalNotification ;
6+ import com .google .common .collect .ForwardingMap ;
67import com .google .common .collect .ImmutableList ;
78import net .minecraft .client .Minecraft ;
89import net .minecraft .client .color .block .BlockColors ;
3637
3738import java .io .IOException ;
3839import java .util .*;
40+ import java .util .concurrent .ConcurrentMap ;
3941import java .util .concurrent .TimeUnit ;
4042import java .util .function .BiConsumer ;
4143import 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
0 commit comments