Remove magic -1 return

This commit is contained in:
themode 2021-12-19 03:22:08 +01:00 committed by TheMode
parent f6db75b9aa
commit 200c94c59e
3 changed files with 3 additions and 4 deletions

View File

@ -124,7 +124,6 @@ public class DynamicChunk extends Chunk {
final Section section = sections[ChunkUtils.getChunkCoordinate(y) - minSection];
final int blockStateId = section.blockPalette()
.get(toChunkRelativeCoordinate(x), y, toChunkRelativeCoordinate(z));
if (blockStateId == -1) return Block.AIR; // Section is empty
return Objects.requireNonNullElse(Block.fromStateId((short) blockStateId), Block.AIR);
}

View File

@ -58,8 +58,8 @@ final class PaletteImpl implements Palette, Cloneable {
throw new IllegalArgumentException("Coordinates must be positive");
}
if (values.length == 0) {
// Section is not loaded, can only be air
return -1;
// Section is not loaded, return default value
return 0;
}
x %= dimension;
y %= dimension;

View File

@ -24,7 +24,7 @@ public class PaletteTest {
public void testPlacement() {
for (Palette palette : palettes) {
final int dimension = palette.dimension();
assertEquals(-1, palette.get(0, 0, 0), "Empty section should return -1");
assertEquals(0, palette.get(0, 0, 0), "Default value should be 0");
palette.set(0, 0, 0, 64);
assertEquals(64, palette.get(0, 0, 0));
assertEquals(64, palette.get(dimension, 0, 0), "Coordinate must be rounded to the palette dimension");