Skip to content

Commit 16c0945

Browse files
authored
Fix crash when loading some resource packs. (#1838)
1 parent e464531 commit 16c0945

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

chunky/src/java/se/llbit/chunky/resources/texturepack/ConditionalTextures.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
import java.io.IOException;
77
import java.io.InputStream;
8-
import java.nio.file.Files;
9-
import java.nio.file.Path;
108

119
/**
1210
* This texture loader will load different textures depending on a texture being available.
@@ -30,11 +28,6 @@ public boolean load(LayeredResourcePacks texturePack) {
3028
return otherwise.load(texturePack);
3129
}
3230

33-
@Override
34-
public boolean loadFromTerrain(BitmapImage[] terrain) {
35-
throw new UnsupportedOperationException("ConditionalTextures doesn't support loadFromTerrain");
36-
}
37-
3831
@Override
3932
protected boolean load(InputStream imageStream) throws IOException, TextureFormatError {
4033
throw new UnsupportedOperationException("Call load(ZipFile) instead!");

chunky/src/java/se/llbit/chunky/resources/texturepack/JsonFontTextureLoader.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ private boolean loadFontDefinitions(LayeredResourcePacks texturePack, String fon
8686
JsonObject definition = fontDefinition.asObject();
8787
if (definition.get("type").stringValue("").equals("bitmap")) {
8888
BitmapImage spritemap;
89-
String texture = definition.get("file").stringValue("").split(":")[1];
89+
String[] textureAndNamespace = definition.get("file").stringValue("").split(":");
90+
String texture = textureAndNamespace.length > 1 ? textureAndNamespace[1] : textureAndNamespace[0];
9091
Optional<LayeredResourcePacks.Entry> texturePath = texturePack.getFirstEntry("assets/minecraft/textures/" + texture);
9192
if (texturePath.isPresent()) {
9293
try (InputStream imageStream = texturePath.get().getInputStream()) {
@@ -106,6 +107,10 @@ private boolean loadFontDefinitions(LayeredResourcePacks texturePack, String fon
106107

107108
int width = spritemap.width / 16;
108109
int height = fontDefinition.asObject().get("height").asInt(8);
110+
if (width <= 0 || height <= 0) {
111+
// some resource packs somehow do this, ignore
112+
continue;
113+
}
109114
int ascent =
110115
fontDefinition
111116
.asObject()

0 commit comments

Comments
 (0)