Skip to content

Commit b5c4b79

Browse files
committed
Merge 1.19.2 into 1.20
2 parents 8677532 + 5e8a111 commit b5c4b79

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
@@ -7,6 +7,7 @@
77
import net.minecraft.client.resources.model.ModelResourceLocation;
88
import net.minecraft.resources.ResourceLocation;
99
import net.minecraft.world.item.Item;
10+
import org.embeddedt.modernfix.dynamicresources.DynamicModelCache;
1011
import org.embeddedt.modernfix.dynamicresources.ModelLocationCache;
1112
import org.embeddedt.modernfix.util.DynamicInt2ObjectMap;
1213
import org.spongepowered.asm.mixin.*;
@@ -32,6 +33,8 @@ public ItemModelShaperMixin() {
3233

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

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

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

6270
/**
@@ -75,5 +83,7 @@ public void register(Item item, ModelResourceLocation location) {
7583
* all models).
7684
**/
7785
@Overwrite
78-
public void rebuildCache() {}
86+
public void rebuildCache() {
87+
this.mfix$itemModelCache.clear();
88+
}
7989
}

0 commit comments

Comments
 (0)