diff --git a/common/src/main/java/org/embeddedt/modernfix/dynamicresources/ItemOverrideBakedModel.java b/common/src/main/java/org/embeddedt/modernfix/dynamicresources/ItemOverrideBakedModel.java index 4f9235bd9..42f431a6e 100644 --- a/common/src/main/java/org/embeddedt/modernfix/dynamicresources/ItemOverrideBakedModel.java +++ b/common/src/main/java/org/embeddedt/modernfix/dynamicresources/ItemOverrideBakedModel.java @@ -11,27 +11,31 @@ import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.Nullable; +import java.lang.ref.WeakReference; import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; /** * Delegate model that stores the location of an actual baked model, for use in ItemOverrides. */ public class ItemOverrideBakedModel implements BakedModel { - private static final Map OVERRIDE_MODELS = new ConcurrentHashMap<>(); public final ResourceLocation realLocation; + private WeakReference realModel = new WeakReference<>(null); private ItemOverrideBakedModel(ResourceLocation realLocation) { this.realLocation = realLocation; } public static ItemOverrideBakedModel of(ResourceLocation realLocation) { - return OVERRIDE_MODELS.computeIfAbsent(realLocation, ItemOverrideBakedModel::new); + return new ItemOverrideBakedModel(realLocation); } public BakedModel getRealModel() { - return DynamicBakedModelProvider.currentInstance.get(realLocation); + BakedModel m = realModel.get(); + if(m == null) { + m = DynamicBakedModelProvider.currentInstance.get(realLocation); + realModel = new WeakReference<>(m); + } + return m; } @Override