1
0
mirror of https://github.com/GeyserMC/Rainbow.git synced 2025-12-19 14:59:16 +00:00

Fix: return empty Optional when a loaded texture is missing from the atlas

This commit is contained in:
Eclipse
2025-10-23 10:30:41 +00:00
parent ad30d7224d
commit e766f0564b

View File

@@ -4,6 +4,8 @@ import com.mojang.blaze3d.platform.NativeImage;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.item.ClientItem; import net.minecraft.client.renderer.item.ClientItem;
import net.minecraft.client.renderer.texture.SpriteContents; import net.minecraft.client.renderer.texture.SpriteContents;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.AtlasManager; import net.minecraft.client.resources.model.AtlasManager;
import net.minecraft.client.resources.model.EquipmentAssetManager; import net.minecraft.client.resources.model.EquipmentAssetManager;
import net.minecraft.client.resources.model.EquipmentClientInfo; import net.minecraft.client.resources.model.EquipmentClientInfo;
@@ -53,8 +55,8 @@ public class MinecraftAssetResolver implements AssetResolver {
} }
@Override @Override
public Optional<TextureResource> getTexture(ResourceLocation atlas, ResourceLocation location) { public Optional<TextureResource> getTexture(ResourceLocation atlasId, ResourceLocation location) {
if (atlas == null) { if (atlasId == null) {
// Not in an atlas - so not animated, probably? // Not in an atlas - so not animated, probably?
return RainbowIO.safeIO(() -> { return RainbowIO.safeIO(() -> {
try (InputStream textureStream = resourceManager.open(Rainbow.decorateTextureLocation(location))) { try (InputStream textureStream = resourceManager.open(Rainbow.decorateTextureLocation(location))) {
@@ -62,10 +64,15 @@ public class MinecraftAssetResolver implements AssetResolver {
} }
}); });
} }
SpriteContents contents = atlasManager.getAtlasOrThrow(atlas).getSprite(location).contents(); TextureAtlas atlas = atlasManager.getAtlasOrThrow(atlasId);
NativeImage original = ((SpriteContentsAccessor) contents).getOriginalImage(); TextureAtlasSprite sprite = atlas.getSprite(location);
if (sprite == atlas.missingSprite()) {
return Optional.empty();
}
NativeImage original = ((SpriteContentsAccessor) sprite.contents()).getOriginalImage();
NativeImage textureCopy = new NativeImage(original.getWidth(), original.getHeight(), false); NativeImage textureCopy = new NativeImage(original.getWidth(), original.getHeight(), false);
textureCopy.copyFrom(original); textureCopy.copyFrom(original);
return Optional.of(new TextureResource(textureCopy, contents.width(), contents.height())); return Optional.of(new TextureResource(textureCopy, sprite.contents().width(), sprite.contents().height()));
} }
} }