From b978eba0fd64fe2816b528d8d4405cdb28d27c06 Mon Sep 17 00:00:00 2001 From: TheMode Date: Thu, 17 Jun 2021 15:37:38 +0200 Subject: [PATCH] Palette cleanup --- .../net/minestom/server/instance/DynamicChunk.java | 3 +++ .../net/minestom/server/instance/palette/Palette.java | 10 ++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/minestom/server/instance/DynamicChunk.java b/src/main/java/net/minestom/server/instance/DynamicChunk.java index 0a7b5beb8..a61c1af4e 100644 --- a/src/main/java/net/minestom/server/instance/DynamicChunk.java +++ b/src/main/java/net/minestom/server/instance/DynamicChunk.java @@ -111,6 +111,9 @@ public class DynamicChunk extends Chunk { public @NotNull Block getBlock(int x, int y, int z) { final Section section = retrieveSection(y); final short blockStateId = section.getBlockAt(x, y, z); + if (blockStateId == -1) { + return Block.AIR; + } Block block = Block.fromStateId(blockStateId); if (block == null) { return Block.AIR; diff --git a/src/main/java/net/minestom/server/instance/palette/Palette.java b/src/main/java/net/minestom/server/instance/palette/Palette.java index aff5e89c6..9d755fffd 100644 --- a/src/main/java/net/minestom/server/instance/palette/Palette.java +++ b/src/main/java/net/minestom/server/instance/palette/Palette.java @@ -4,6 +4,7 @@ import it.unimi.dsi.fastutil.shorts.Short2ShortLinkedOpenHashMap; import it.unimi.dsi.fastutil.shorts.Short2ShortOpenHashMap; import net.minestom.server.MinecraftServer; import net.minestom.server.instance.Chunk; +import net.minestom.server.instance.block.Block; import net.minestom.server.utils.MathUtils; import net.minestom.server.utils.clone.PublicCloneable; import org.jetbrains.annotations.NotNull; @@ -76,8 +77,7 @@ public class Palette implements PublicCloneable { } // Check if the new block is air, used for counting none air blocks. - // FIXME: once block data is working - final boolean isAir = blockId == 0;//Block.fromStateId(blockId).isAir(); + final boolean isAir = Block.fromStateId(blockId).isAir(); // Change to palette value blockId = getPaletteIndex(blockId); @@ -94,9 +94,7 @@ public class Palette implements PublicCloneable { final long value = block >> bitIndex & clear; - // FIXME: once block data is working - final boolean isCurrentAir = (hasPalette ? paletteBlockMap.get((short) value) : (short) value) == 0; - //Block.fromStateId(hasPalette ? paletteBlockMap.get((short) value) : (short) value).isAir(); + final boolean isCurrentAir = Block.fromStateId(hasPalette ? paletteBlockMap.get((short) value) : (short) value).isAir(); block |= clear << bitIndex; block ^= clear << bitIndex; @@ -115,7 +113,7 @@ public class Palette implements PublicCloneable { public short getBlockAt(int x, int y, int z) { if (blocks.length == 0) { // Section is not loaded, can only be air - return 0; + return -1; } final int sectionIdentifier = getSectionIndex(x, y, z);