Make texture-gallery stronger against corrupting

This commit is contained in:
Lukas Rieger (Blue) 2022-11-28 00:04:09 +01:00
parent b9b7aaffc9
commit 0fc1424021
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
2 changed files with 15 additions and 0 deletions

View File

@ -47,6 +47,10 @@ public void writeTexturesFile(ResourcePack resourcePack, OutputStream out) throw
ordinalMap.forEach((textureResourcePath, ordinal) -> {
Texture texture = textureResourcePath.getResource(resourcePack::getTexture);
if (texture != null) textures[ordinal] = texture;
// make sure the resource-path doesn't get lost
if (textures[ordinal].getResourcePath().equals(ResourcePack.MISSING_TEXTURE))
textures[ordinal] = Texture.missing(textureResourcePath);
});
try (Writer writer = new OutputStreamWriter(out)) {

View File

@ -37,6 +37,13 @@ private Texture(ResourcePath<Texture> resourcePath, Color color, boolean halfTra
this.texture = texture;
}
private Texture(ResourcePath<Texture> resourcePath) {
this.resourcePath = resourcePath;
this.color = MISSING.color;
this.halfTransparent = MISSING.halfTransparent;
this.texture = MISSING.texture;
}
public ResourcePath<Texture> getResourcePath() {
return resourcePath;
}
@ -131,4 +138,8 @@ private static Color calculateColor(BufferedImage image){
return new Color().set(red, green, blue, alpha, false);
}
public static Texture missing(ResourcePath<Texture> resourcePath) {
return new Texture(resourcePath);
}
}