11package org .embeddedt .modernfix .common .mixin .perf .faster_texture_stitching ;
22
3+ import com .google .common .collect .ImmutableList ;
34import com .mojang .datafixers .util .Pair ;
45import it .unimi .dsi .fastutil .objects .ObjectArrayList ;
56import net .minecraft .client .renderer .texture .Stitcher ;
7+ import net .minecraft .client .renderer .texture .StitcherException ;
68import org .embeddedt .modernfix .ModernFix ;
79import org .embeddedt .modernfix .annotation .ClientOnlyMixin ;
810import org .embeddedt .modernfix .platform .ModernFixPlatformHooks ;
1719import java .util .Comparator ;
1820import java .util .List ;
1921import java .util .Set ;
22+ import java .util .stream .Stream ;
2023
2124@ Mixin (Stitcher .class )
2225@ ClientOnlyMixin
@@ -28,6 +31,8 @@ public class StitcherMixin {
2831 @ Shadow private int storageY ;
2932
3033 @ Shadow @ Final private static Comparator <Stitcher .Holder > HOLDER_COMPARATOR ;
34+ @ Shadow @ Final private int maxWidth ;
35+ @ Shadow @ Final private int maxHeight ;
3136 private List <StbStitcher .LoadableSpriteInfo > loadableSpriteInfos ;
3237
3338 /**
@@ -48,6 +53,13 @@ private void stitchFast(CallbackInfo ci) {
4853 Pair <Pair <Integer , Integer >, List <StbStitcher .LoadableSpriteInfo >> packingInfo = StbStitcher .packRects (aholder );
4954 this .storageX = packingInfo .getFirst ().getFirst ();
5055 this .storageY = packingInfo .getFirst ().getSecond ();
56+
57+ // Detect an oversized atlas generated in the previous step.
58+ if (this .storageX > this .maxWidth || this .storageY > this .maxHeight ) {
59+ ModernFix .LOGGER .error ("Requested atlas size {}x{} exceeds maximum of {}x{}" , this .storageX , this .storageY , this .maxWidth , this .maxHeight );
60+ throw new StitcherException (aholder [0 ].spriteInfo , Stream .of (aholder ).map (arg -> arg .spriteInfo ).collect (ImmutableList .toImmutableList ()));
61+ }
62+
5163 this .loadableSpriteInfos = packingInfo .getSecond ();
5264 }
5365
0 commit comments