Skip to content

Commit 25eb576

Browse files
committed
Small tidy-ups
1 parent ed13c0b commit 25eb576

31 files changed

+87
-96
lines changed

core/src/main/java/de/bluecolored/bluemap/core/logger/LogFormatter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public LogFormatter(String format) {
4848
* @param record the log record to be formatted.
4949
* @return the formatted log
5050
*/
51+
@Override
5152
public String format(LogRecord record) {
5253
ZonedDateTime zdt = ZonedDateTime.ofInstant(
5354
record.getInstant(), ZoneId.systemDefault());

core/src/main/java/de/bluecolored/bluemap/core/map/TextureGallery.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.jetbrains.annotations.Nullable;
3535

3636
import java.io.*;
37+
import java.nio.charset.StandardCharsets;
3738
import java.util.Arrays;
3839
import java.util.Comparator;
3940
import java.util.HashMap;
@@ -99,7 +100,7 @@ public void writeTexturesFile(OutputStream out) throws IOException {
99100
textures[ordinal] = texture;
100101
});
101102

102-
try (Writer writer = new OutputStreamWriter(out)) {
103+
try (Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8)) {
103104
GSON.toJson(textures, Texture[].class, writer);
104105
} catch (JsonIOException ex) {
105106
throw new IOException(ex);
@@ -108,7 +109,7 @@ public void writeTexturesFile(OutputStream out) throws IOException {
108109

109110
public static TextureGallery readTexturesFile(InputStream in) throws IOException {
110111
TextureGallery gallery = new TextureGallery();
111-
try (Reader reader = new InputStreamReader(in)) {
112+
try (Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8)) {
112113
Texture[] textures = GSON.fromJson(reader, Texture[].class);
113114
if (textures == null) throw new IOException("Texture data is empty!");
114115
gallery.nextId = textures.length;

core/src/main/java/de/bluecolored/bluemap/core/map/hires/ArrayTileModel.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ public ArrayTileModel setMaterialIndex(int face, int m) {
186186
return this;
187187
}
188188

189+
@Override
189190
public ArrayTileModel invertOrientation(int face) {
190191
int index;
191192
float x, y, z;

core/src/main/java/de/bluecolored/bluemap/core/map/hires/block/LiquidModelRenderer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public LiquidModelRenderer(ResourcePack resourcePack, TextureGallery textureGall
9797
for (int i = 0; i < uvs.length; i++) uvs[i] = new VectorM2f(0, 0);
9898
}
9999

100+
@Override
100101
public void render(BlockNeighborhood block, Variant variant, TileModelView blockModel, Color color) {
101102
this.block = block;
102103
this.blockState = block.getBlockState();

core/src/main/java/de/bluecolored/bluemap/core/map/hires/block/ResourceModelRenderer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import de.bluecolored.bluemap.core.world.block.ExtendedBlock;
5252
import lombok.Getter;
5353

54-
import java.util.EnumMap;
5554
import java.util.function.Function;
5655

5756
/**
@@ -72,7 +71,6 @@ public class ResourceModelRenderer implements BlockRenderer {
7271
private final VectorM2f[] uvs = new VectorM2f[4];
7372
private final Color tintColor = new Color();
7473
private final Color mapColor = new Color();
75-
private final EnumMap<Direction, Float> uvLockRotationCache = new EnumMap<>(Direction.class);
7674

7775
private BlockNeighborhood block;
7876
private Variant variant;
@@ -92,6 +90,7 @@ public ResourceModelRenderer(ResourcePack resourcePack, TextureGallery textureGa
9290
for (int i = 0; i < rawUvs.length; i++) rawUvs[i] = new VectorM2f(0, 0);
9391
}
9492

93+
@Override
9594
public void render(BlockNeighborhood block, Variant variant, TileModelView blockModel, Color color) {
9695
this.block = block;
9796
this.blockModel = blockModel;

core/src/main/java/de/bluecolored/bluemap/core/resources/BlockColorCalculatorFactory.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import de.bluecolored.bluemap.core.BlueMap;
3232
import de.bluecolored.bluemap.core.util.Key;
3333
import de.bluecolored.bluemap.core.util.math.Color;
34-
import de.bluecolored.bluemap.core.world.BlockProperties;
3534
import de.bluecolored.bluemap.core.world.BlockState;
3635
import de.bluecolored.bluemap.core.world.biome.Biome;
3736
import de.bluecolored.bluemap.core.world.block.BlockAccess;
@@ -42,7 +41,10 @@
4241
import java.io.IOException;
4342
import java.nio.file.Files;
4443
import java.nio.file.Path;
45-
import java.util.*;
44+
import java.util.ArrayList;
45+
import java.util.Collections;
46+
import java.util.List;
47+
import java.util.Map;
4648
import java.util.concurrent.ConcurrentHashMap;
4749
import java.util.concurrent.TimeUnit;
4850

@@ -89,32 +91,22 @@ public void load(Path configFile) throws IOException {
8991

9092
ColorFunction colorFunction;
9193
switch (value) {
92-
case "@foliage":
93-
colorFunction = BlockColorCalculator::getBlendedFoliageColor;
94-
break;
95-
case "@dry_foliage":
96-
colorFunction = BlockColorCalculator::getBlendedDryFoliageColor;
97-
break;
98-
case "@grass":
99-
colorFunction = BlockColorCalculator::getBlendedGrassColor;
100-
break;
101-
case "@water":
102-
colorFunction = BlockColorCalculator::getBlendedWaterColor;
103-
break;
104-
case "@redstone":
105-
colorFunction = BlockColorCalculator::getRedstoneColor;
106-
break;
107-
default:
94+
case "@foliage" -> colorFunction = BlockColorCalculator::getBlendedFoliageColor;
95+
case "@dry_foliage" -> colorFunction = BlockColorCalculator::getBlendedDryFoliageColor;
96+
case "@grass" -> colorFunction = BlockColorCalculator::getBlendedGrassColor;
97+
case "@water" -> colorFunction = BlockColorCalculator::getBlendedWaterColor;
98+
case "@redstone" -> colorFunction = BlockColorCalculator::getRedstoneColor;
99+
default -> {
108100
final Color color = new Color();
109101
color.parse(value).premultiplied();
110102
colorFunction = (calculator, block, target) -> target.set(color);
111-
break;
103+
}
112104
}
113105

114106
BlockStateMapping<ColorFunction> mapping = new BlockStateMapping<>(key, colorFunction);
115107

116108
// don't overwrite already present values, higher priority resources are loaded first
117-
mappings.computeIfAbsent(key.getId(), k -> new LinkedList<>()).add(mapping);
109+
mappings.computeIfAbsent(key.getId(), k -> new ArrayList<>(1)).add(mapping);
118110
}
119111

120112
json.endObject();

core/src/main/java/de/bluecolored/bluemap/core/resources/BlockPropertiesConfig.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
import java.io.IOException;
3434
import java.nio.file.Files;
3535
import java.nio.file.Path;
36+
import java.util.ArrayList;
3637
import java.util.Collections;
37-
import java.util.LinkedList;
3838
import java.util.List;
3939
import java.util.Map;
4040
import java.util.concurrent.ConcurrentHashMap;
@@ -61,20 +61,20 @@ public void load(Path configFile) throws IOException {
6161
json.beginObject();
6262
while (json.hasNext()) {
6363
switch (json.nextName()) {
64-
case "culling": bsValueBuilder.culling(json.nextBoolean()); break;
65-
case "occluding": bsValueBuilder.occluding(json.nextBoolean()); break;
66-
case "alwaysWaterlogged": bsValueBuilder.alwaysWaterlogged(json.nextBoolean()); break;
67-
case "randomOffset": bsValueBuilder.randomOffset(json.nextBoolean()); break;
68-
case "cullingIdentical": bsValueBuilder.cullingIdentical(json.nextBoolean()); break;
69-
default: break;
64+
case "culling" -> bsValueBuilder.culling(json.nextBoolean());
65+
case "occluding" -> bsValueBuilder.occluding(json.nextBoolean());
66+
case "alwaysWaterlogged" -> bsValueBuilder.alwaysWaterlogged(json.nextBoolean());
67+
case "randomOffset" -> bsValueBuilder.randomOffset(json.nextBoolean());
68+
case "cullingIdentical" -> bsValueBuilder.cullingIdentical(json.nextBoolean());
69+
default -> {}
7070
}
7171
}
7272
json.endObject();
7373

7474
BlockStateMapping<BlockProperties> mapping = new BlockStateMapping<>(bsKey, bsValueBuilder.build());
7575

7676
// don't overwrite already present values, higher priority resources are loaded first
77-
mappings.computeIfAbsent(bsKey.getId(), k -> new LinkedList<>()).add(mapping);
77+
mappings.computeIfAbsent(bsKey.getId(), k -> new ArrayList<>(1)).add(mapping);
7878
}
7979
json.endObject();
8080
}

core/src/main/java/de/bluecolored/bluemap/core/resources/adapter/AbstractTypeAdapterFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public void write(JsonWriter out, T value, Gson gson) throws IOException {
4949
public abstract T read(JsonReader in, Gson gson) throws IOException;
5050

5151
@SuppressWarnings("unchecked")
52+
@Override
5253
public <U> TypeAdapter<U> create(Gson gson, TypeToken<U> type) {
5354
if (!type.getRawType().isAssignableFrom(this.type)) return null;
5455
return (TypeAdapter<U>) new Adapter(gson);

core/src/main/java/de/bluecolored/bluemap/core/resources/adapter/ColorAdapter.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public Color read(JsonReader in) throws IOException {
5050
Color value = new Color();
5151
JsonToken token = in.peek();
5252
switch (token) {
53-
case BEGIN_ARRAY:
53+
case BEGIN_ARRAY -> {
5454
in.beginArray();
5555
value.set(
5656
(float) in.nextDouble(),
@@ -60,8 +60,8 @@ public Color read(JsonReader in) throws IOException {
6060
false
6161
);
6262
in.endArray();
63-
break;
64-
case BEGIN_OBJECT:
63+
}
64+
case BEGIN_OBJECT -> {
6565
value.a = 1f;
6666
in.beginObject();
6767
while (in.hasNext()) {
@@ -76,18 +76,15 @@ public Color read(JsonReader in) throws IOException {
7676
}
7777
}
7878
in.endObject();
79-
break;
80-
case STRING:
81-
value.parse(in.nextString());
82-
break;
83-
case NUMBER:
79+
}
80+
case STRING -> value.parse(in.nextString());
81+
case NUMBER -> {
8482
int color = in.nextInt();
8583
if ((color & 0xFF000000) == 0) color = color | 0xFF000000; // assume full alpha if not specified
8684
value.set(color);
87-
break;
88-
case NULL:
89-
break;
90-
default: throw new IOException("Unexpected token while parsing Color:" + token);
85+
}
86+
case NULL -> {}
87+
default -> throw new IOException("Unexpected token while parsing Color:" + token);
9188
}
9289
return value;
9390
}

core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/ResourcePack.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public ResourcePack(PackVersion packVersion) {
115115
extensions.put(extensionType, extensionType.create(this));
116116
}
117117

118+
@Override
118119
public synchronized void loadResources(Iterable<Path> roots) throws IOException, InterruptedException {
119120
Logger.global.logInfo("Loading resources...");
120121

@@ -284,7 +285,7 @@ private void loadResources(Path root) throws IOException {
284285

285286
} catch (RuntimeException ex) {
286287
Throwable cause = ex.getCause();
287-
if (cause instanceof IOException) throw (IOException) cause;
288+
if (cause instanceof IOException ioEx) throw ioEx;
288289
if (cause != null) throw new IOException(cause);
289290
throw new IOException(ex);
290291
}

0 commit comments

Comments
 (0)