77import net .minecraft .client .resources .model .ModelResourceLocation ;
88import net .minecraft .resources .ResourceLocation ;
99import net .minecraft .world .item .Item ;
10+ import org .embeddedt .modernfix .dynamicresources .DynamicModelCache ;
1011import org .embeddedt .modernfix .dynamicresources .ModelLocationCache ;
1112import org .embeddedt .modernfix .util .DynamicInt2ObjectMap ;
1213import 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