Skip to content

Commit 5e8a111

Browse files
committed
Merge 1.18 into 1.19.2
2 parents 559bdb6 + fe65ffa commit 5e8a111

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/ItemModelShaperMixin.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.minecraft.client.resources.model.ModelManager;
77
import net.minecraft.client.resources.model.ModelResourceLocation;
88
import net.minecraft.world.item.Item;
9+
import org.embeddedt.modernfix.dynamicresources.DynamicModelCache;
910
import org.embeddedt.modernfix.dynamicresources.ModelLocationCache;
1011
import org.embeddedt.modernfix.util.DynamicInt2ObjectMap;
1112
import org.spongepowered.asm.mixin.*;
@@ -31,6 +32,8 @@ public ItemModelShaperMixin() {
3132

3233
private static final ModelResourceLocation SENTINEL_VANILLA = new ModelResourceLocation("modernfix", "sentinel");
3334

35+
private final DynamicModelCache<Item> mfix$itemModelCache = new DynamicModelCache<>(k -> this.mfix$getModelForItem((Item)k), true);
36+
3437
@Inject(method = "<init>", at = @At("RETURN"))
3538
private void replaceLocationMap(CallbackInfo ci) {
3639
overrideLocationsVanilla = new HashMap<>();
@@ -47,15 +50,20 @@ private void replaceLocationMap(CallbackInfo ci) {
4750
return map;
4851
}
4952

53+
54+
private BakedModel mfix$getModelForItem(Item item) {
55+
ModelResourceLocation map = mfix$getLocation(item);
56+
return map == null ? null : getModelManager().getModel(map);
57+
}
58+
5059
/**
5160
* @author embeddedt
5261
* @reason Get the stored location for that item and meta, and get the model
5362
* from that location from the model manager.
5463
**/
5564
@Overwrite
5665
public BakedModel getItemModel(Item item) {
57-
ModelResourceLocation map = mfix$getLocation(item);
58-
return map == null ? null : getModelManager().getModel(map);
66+
return this.mfix$itemModelCache.get(item);
5967
}
6068

6169
/**
@@ -74,5 +82,7 @@ public void register(Item item, ModelResourceLocation location) {
7482
* all models).
7583
**/
7684
@Overwrite
77-
public void rebuildCache() {}
85+
public void rebuildCache() {
86+
this.mfix$itemModelCache.clear();
87+
}
7888
}

0 commit comments

Comments
 (0)