diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/ItemModelShaperMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/ItemModelShaperMixin.java index 398ac679..6725a87a 100644 --- a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/ItemModelShaperMixin.java +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/ItemModelShaperMixin.java @@ -7,6 +7,7 @@ import net.minecraft.client.resources.model.ModelManager; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; +import org.embeddedt.modernfix.dynamicresources.DynamicModelCache; import org.embeddedt.modernfix.dynamicresources.ModelLocationCache; import org.embeddedt.modernfix.util.DynamicInt2ObjectMap; import org.spongepowered.asm.mixin.*; @@ -32,6 +33,8 @@ public abstract class ItemModelShaperMixin { private static final ModelResourceLocation SENTINEL_VANILLA = new ModelResourceLocation(new ResourceLocation("modernfix", "sentinel"), "sentinel"); + private final DynamicModelCache mfix$itemModelCache = new DynamicModelCache<>(k -> this.mfix$getModelForItem((Item)k), true); + @Inject(method = "", at = @At("RETURN")) private void replaceLocationMap(CallbackInfo ci) { overrideLocationsVanilla = new HashMap<>(); @@ -48,6 +51,12 @@ public abstract class ItemModelShaperMixin { return map; } + + private BakedModel mfix$getModelForItem(Item item) { + ModelResourceLocation map = mfix$getLocation(item); + return map == null ? null : getModelManager().getModel(map); + } + /** * @author embeddedt * @reason Get the stored location for that item and meta, and get the model @@ -55,8 +64,7 @@ public abstract class ItemModelShaperMixin { **/ @Overwrite public BakedModel getItemModel(Item item) { - ModelResourceLocation map = mfix$getLocation(item); - return map == null ? null : getModelManager().getModel(map); + return this.mfix$itemModelCache.get(item); } /** @@ -75,5 +83,7 @@ public abstract class ItemModelShaperMixin { * all models). **/ @Overwrite - public void rebuildCache() {} + public void rebuildCache() { + this.mfix$itemModelCache.clear(); + } }