Skip to content

Commit

Permalink
Some fixes, warnings, and optimization.
Browse files Browse the repository at this point in the history
  • Loading branch information
kvverti committed Mar 13, 2022
1 parent b66ace1 commit 8c9309b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,9 @@ private static ColormapProperties loadFromJson(Reader json, Identifier id, boole
if(settings == null) {
settings = new Settings();
}
} catch(JsonSyntaxException e) {
log.error("Error parsing {}: {}", id, e.getMessage());
} catch(Exception e) {
// any one of a number of exceptions could have been thrown during deserialization
log.error("Error loading {}: {}", id, e.getMessage());
settings = new Settings();
}
if(settings.format == null) {
Expand All @@ -361,7 +362,10 @@ private static ColormapProperties loadFromJson(Reader json, Identifier id, boole
}
}
} else {
// disable `blocks`, `grid`, and `biomes` for non-custom colormaps
// disable `blocks`, `grid`, and `biomes` for non-custom colormaps, warn if they are present
if(settings.biomes != null || settings.grid != null || settings.blocks != null) {
log.warn("{}: found `biomes`, `grid`, or `blocks` properties in a provided colormap; these will be ignored", id);
}
settings.biomes = null;
settings.grid = null;
settings.blocks = Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ public static PropertyImage loadColormap(ResourceManager manager, Identifier id,
}
try(Resource rsc = manager.getResource(props.getSource()); InputStream in = rsc.getInputStream()) {
NativeImage image = NativeImage.read(in);
for(int x = 0; x < image.getWidth(); x++) {
for(int y = 0; y < image.getHeight(); y++) {
if(ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) {
// swap the red and blue channels of every pixel, because the biome
// colormap expects ARGB, but NativeImage is ABGR
if(ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) {
// swap the red and blue channels of every pixel, because the biome
// colormap expects ARGB, but NativeImage is ABGR
for(int x = 0; x < image.getWidth(); x++) {
for(int y = 0; y < image.getHeight(); y++) {
int pix = image.getColor(x, y);
int tmp = (pix & 0xff0000) >> 16;
tmp |= (pix & 0x0000ff) << 16;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.ArrayList;

import com.google.common.collect.ImmutableList;
import com.google.gson.JsonSyntaxException;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
Expand All @@ -43,7 +44,8 @@ public void write(JsonWriter jsonWriter, GridEntry gridEntry) {
public GridEntry read(JsonReader in) throws IOException {
switch(in.peek()) {
case NULL -> {
return null;
in.nextNull();
throw new JsonSyntaxException("required nonnull");
}
case STRING -> {
var biomeId = this.idAdapter.read(in);
Expand All @@ -66,6 +68,7 @@ public GridEntry read(JsonReader in) throws IOException {
}
case "column" -> gridEntry.column = in.nextInt();
case "width" -> gridEntry.width = in.nextInt();
default -> in.skipValue();
}
}
in.endObject();
Expand Down

0 comments on commit 8c9309b

Please sign in to comment.