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