77import net .minecraft .client .renderer .texture .TextureAtlasSprite ;
88import net .minecraft .client .resources .model .Material ;
99import net .minecraft .data .AtlasIds ;
10- import net .minecraft .resources .Identifier ;
1110import net .minecraft .util .Util ;
11+ import org .geysermc .rainbow .Rainbow ;
1212import org .geysermc .rainbow .RainbowIO ;
1313import org .geysermc .rainbow .mapping .PackContext ;
1414import org .geysermc .rainbow .mixin .SpriteContentsAccessor ;
@@ -37,7 +37,7 @@ public Optional<TextureAtlasSprite> getSprite(String key) {
3737
3838 public static StitchedTextures stitchModelTextures (TextureSlots textures , PackContext context ) {
3939 Map <String , Material > materials = ((TextureSlotsAccessor ) textures ).getResolvedValues ();
40- SpriteLoader .Preparations preparations = prepareStitching (materials .values ().stream (). map ( Material :: texture ) , context );
40+ SpriteLoader .Preparations preparations = prepareStitching (materials .values ().stream (), context );
4141
4242 Map <String , TextureAtlasSprite > sprites = new HashMap <>();
4343 for (Map .Entry <String , Material > material : materials .entrySet ()) {
@@ -50,21 +50,21 @@ public static StitchedTextures stitchModelTextures(TextureSlots textures, PackCo
5050 return new StitchedTextures (Map .copyOf (sprites ), () -> stitchTextureAtlas (preparations ), preparations .width (), preparations .height ());
5151 }
5252
53- private static SpriteLoader .Preparations prepareStitching (Stream <Identifier > textures , PackContext context ) {
54- // Atlas ID doesn't matter much here, but BLOCKS is the most appropriate
55- SpriteLoader spriteLoader = new SpriteLoader (AtlasIds .BLOCKS , MAX_TEXTURE_SIZE );
56- List <SpriteContents > sprites = textures .distinct ()
57- .map (texture -> readSpriteContents (texture , context ))
53+ private static SpriteLoader .Preparations prepareStitching (Stream <Material > materials , PackContext context ) {
54+ // Atlas ID doesn't matter much here, but ITEMS is the most appropriate (though not always right)
55+ SpriteLoader spriteLoader = new SpriteLoader (AtlasIds .ITEMS , MAX_TEXTURE_SIZE );
56+ List <SpriteContents > sprites = materials .distinct ()
57+ .map (material -> readSpriteContents (material , context ))
5858 .<SpriteContents >mapMulti (Optional ::ifPresent )
5959 .toList ();
6060 return ((SpriteLoaderAccessor ) spriteLoader ).invokeStitch (sprites , 0 , Util .backgroundExecutor ());
6161 }
6262
63- private static Optional <SpriteContents > readSpriteContents (Identifier identifier , PackContext context ) {
63+ private static Optional <SpriteContents > readSpriteContents (Material material , PackContext context ) {
6464 return RainbowIO .safeIO (() -> {
65- try (TextureResource texture = context .assetResolver ().getTexture ( AtlasIds . BLOCKS , identifier ).orElse (null )) {
65+ try (TextureResource texture = context .assetResolver ().getTextureSafely ( Rainbow . getAtlasIdFromMaterial ( material ), material . texture () ).orElse (null )) {
6666 if (texture != null ) {
67- return new SpriteContents (identifier , texture .sizeOfFrame (), texture .getFirstFrame (true ));
67+ return new SpriteContents (material . texture () , texture .sizeOfFrame (), texture .getFirstFrame (true ));
6868 }
6969 }
7070 return null ;
0 commit comments