From 7c1d7a9cc264cba02d9eb4051231a2b57d24417c Mon Sep 17 00:00:00 2001 From: "Lukas Rieger (Blue)" Date: Wed, 14 Jun 2023 20:33:25 +0200 Subject: [PATCH] First mock of an improved nether-render mode --- .../bluemap/core/mca/MCAChunk.java | 38 ++++++++++++++++--- .../bluecolored/bluemap/core/world/Block.java | 5 ++- .../bluemap/core/world/BlockState.java | 17 ++++++++- .../bluecolored/bluemap/core/world/Chunk.java | 2 + .../bluemap/core/world/EmptyChunk.java | 5 +++ 5 files changed, 60 insertions(+), 7 deletions(-) diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/MCAChunk.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/MCAChunk.java index b85e3276..c81242d7 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/MCAChunk.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/MCAChunk.java @@ -30,25 +30,33 @@ import de.bluecolored.bluemap.core.world.LightData; import net.querz.nbt.CompoundTag; import java.io.IOException; +import java.util.Arrays; public abstract class MCAChunk implements Chunk { private final MCAWorld world; private final int dataVersion; + private int[] netherCeilingHeights; + protected MCAChunk() { - this.world = null; - this.dataVersion = -1; + this(null, -1); } protected MCAChunk(MCAWorld world) { - this.world = world; - this.dataVersion = -1; + this(world, -1); } protected MCAChunk(MCAWorld world, CompoundTag chunkTag) { + this(world, chunkTag.getInt("DataVersion")); + } + + private MCAChunk(MCAWorld world, int dataVersion) { this.world = world; - dataVersion = chunkTag.getInt("DataVersion"); + this.dataVersion = dataVersion; + + this.netherCeilingHeights = new int[16 * 16]; + Arrays.fill(this.netherCeilingHeights, Integer.MIN_VALUE); } @Override @@ -86,6 +94,26 @@ public abstract class MCAChunk implements Chunk { @Override public int getOceanFloorY(int x, int z) { return 0; } + @Override + public int getNetherCeilingY(int x, int z) { + int lx = x & 0xF, lz = z & 0xF; + int i = lz * 16 + lx; + int y = netherCeilingHeights[i]; + + if (y == Integer.MIN_VALUE) { + int maxY = getMaxY(x, z); + int minY = getMinY(x, z); + + for (y = Math.min(maxY, 120); y >= minY; y--){ + if (!getBlockState(x, y, z).isNetherCeiling()) break; + } + + netherCeilingHeights[i] = y; + } + + return y; + } + protected MCAWorld getWorld() { return world; } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/Block.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/Block.java index a3b9b14d..d8ab28bd 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/Block.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/Block.java @@ -136,7 +136,10 @@ public class Block> { } public BlockState getBlockState() { - if (blockState == null) blockState = getChunk().getBlockState(x, y, z); + if (blockState == null){ + if (y > getChunk().getNetherCeilingY(x, z)) blockState = BlockState.AIR; + else blockState = getChunk().getBlockState(x, y, z); + } return blockState; } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/BlockState.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/BlockState.java index f39daaaa..2101c4ff 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/BlockState.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/BlockState.java @@ -53,7 +53,7 @@ public class BlockState extends Key { private final Map properties; private final Property[] propertiesArray; - private final boolean isAir, isWater, isWaterlogged; + private final boolean isAir, isWater, isWaterlogged, isNetherCeiling; private int liquidLevel = -1, redstonePower = -1; public BlockState(String value) { @@ -82,6 +82,17 @@ public class BlockState extends Key { this.isWater = "minecraft:water".equals(this.getFormatted()); this.isWaterlogged = "true".equals(properties.get("waterlogged")); + this.isNetherCeiling = + "minecraft:bedrock".equals(this.getFormatted()) || + "minecraft:netherrack".equals(this.getFormatted()) || + "minecraft:nether_quartz_ore".equals(this.getFormatted()) || + "minecraft:lava".equals(this.getFormatted()) || + "minecraft:soul_sand".equals(this.getFormatted()) || + "minecraft:basalt".equals(this.getFormatted()) || + "minecraft:blackstone".equals(this.getFormatted()) || + "minecraft:soul_soil".equals(this.getFormatted()) || + "minecraft:nether_gold_ore".equals(this.getFormatted()) || + "minecraft:ancient_debris".equals(this.getFormatted()); } /** @@ -109,6 +120,10 @@ public class BlockState extends Key { return isWaterlogged; } + public boolean isNetherCeiling() { + return isNetherCeiling; + } + public int getLiquidLevel() { if (liquidLevel == -1) { try { diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/Chunk.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/Chunk.java index 2639b8b0..4baaf376 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/Chunk.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/Chunk.java @@ -44,4 +44,6 @@ public interface Chunk { int getOceanFloorY(int x, int z); + int getNetherCeilingY(int x, int z); + } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/EmptyChunk.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/EmptyChunk.java index 089dedd8..5dd0299f 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/EmptyChunk.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/EmptyChunk.java @@ -69,4 +69,9 @@ public class EmptyChunk implements Chunk { @Override public int getOceanFloorY(int x, int z) { return 0; } + @Override + public int getNetherCeilingY(int x, int z) { + return 0; + } + }