From c6019c722d641ed68b00f690a1d1aef6295dcd9c Mon Sep 17 00:00:00 2001 From: "Lukas Rieger (Blue)" Date: Wed, 19 Oct 2022 16:25:25 +0200 Subject: [PATCH] Little improvements here and there --- .../hires/blockmodel/LiquidModelBuilder.java | 17 ++++------ .../bluemap/core/mca/ChunkAnvil118.java | 9 ++--- .../BlockColorCalculatorFactory.java | 26 ++++++--------- .../bluemap/core/world/BlockState.java | 33 ++++++++++++++++++- .../bluemap/bukkit/BukkitCommandSource.java | 2 +- 5 files changed, 52 insertions(+), 35 deletions(-) diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/LiquidModelBuilder.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/LiquidModelBuilder.java index af6cd2ed..142ddbae 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/LiquidModelBuilder.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/LiquidModelBuilder.java @@ -110,8 +110,7 @@ private void build() { (renderSettings.isCaveDetectionUsesBlockLight() ? block.getBlockLightLevel() : block.getSunLightLevel()) == 0f ) return; - int level = getLiquidLevel(blockState); - + int level = blockState.getLiquidLevel(); if (level < 8 && !(level == 0 && isSameLiquid(block.getNeighborBlock(0, 1, 0)))){ corners[4].y = getLiquidCornerHeight(-1, -1); corners[5].y = getLiquidCornerHeight(-1, 0); @@ -196,7 +195,7 @@ private float getLiquidCornerHeight(int x, int z){ neighbor = block.getNeighborBlock(ix, 0, iz); neighborBlockState = neighbor.getBlockState(); if (isSameLiquid(neighbor)){ - if (getLiquidLevel(neighborBlockState) == 0) return 14f; + if (neighborBlockState.getLiquidLevel() == 0) return 14f; sumHeight += getLiquidBaseHeight(neighborBlockState); count++; @@ -216,24 +215,20 @@ else if (!isLiquidBlockingBlock(neighborBlockState)){ } private boolean isLiquidBlockingBlock(BlockState blockState){ - return !blockState.equals(BlockState.AIR); + return !blockState.isAir(); } + @SuppressWarnings("StringEquality") private boolean isSameLiquid(ExtendedBlock block){ - if (block.getBlockState().getFormatted().equals(this.blockState.getFormatted())) return true; + if (block.getBlockState().getFormatted() == this.blockState.getFormatted()) return true; return this.blockState.isWater() && (block.getBlockState().isWaterlogged() || block.getProperties().isAlwaysWaterlogged()); } private float getLiquidBaseHeight(BlockState block){ - int level = getLiquidLevel(block); + int level = block.getLiquidLevel(); return level >= 8 ? 16f : 14f - level * 1.9f; } - private int getLiquidLevel(BlockState block){ - String levelString = block.getProperties().get("level"); - return levelString != null ? Integer.parseInt(levelString) : 0; - } - private final MatrixM3f uvTransform = new MatrixM3f(); private boolean createElementFace(Direction faceDir, VectorM3f c0, VectorM3f c1, VectorM3f c2, VectorM3f c3, Color color, int stillTextureId, int flowTextureId) { Vector3i faceDirVector = faceDir.toVector(); diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil118.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil118.java index d4976291..dca4103a 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil118.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil118.java @@ -35,8 +35,6 @@ @SuppressWarnings("FieldMayBeFinal") public class ChunkAnvil118 extends MCAChunk { - private static final String AIR_ID = "minecraft:air"; - private boolean isGenerated; private boolean hasLight; @@ -74,7 +72,7 @@ public ChunkAnvil118(MCAWorld world, CompoundTag chunkTag) { ListTag paletteTag = (ListTag) blockStatesTag.getListTag("palette"); if (paletteTag == null) continue; if (paletteTag.size() == 0) continue; - if (paletteTag.size() == 1 && AIR_ID.equals(paletteTag.get(0).getString("Name"))) continue; + if (paletteTag.size() == 1 && BlockState.AIR.getFormatted().equals(paletteTag.get(0).getString("Name"))) continue; Section section = new Section(sectionTag); int y = section.getSectionY(); @@ -214,11 +212,10 @@ public Section(CompoundTag sectionData) { } private BlockState readBlockStatePaletteEntry(CompoundTag paletteEntry) { - String id = paletteEntry.getString("Name"); //shortcut to save time and memory - if (AIR_ID.equals(id)) return BlockState.AIR; + String id = paletteEntry.getString("Name"); + if (BlockState.AIR.getFormatted().equals(id)) return BlockState.AIR; //shortcut to save time and memory Map properties = new LinkedHashMap<>(); - if (paletteEntry.containsKey("Properties")) { CompoundTag propertiesTag = paletteEntry.getCompoundTag("Properties"); for (Entry> property : propertiesTag) { diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/BlockColorCalculatorFactory.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/BlockColorCalculatorFactory.java index d19498f3..1719f2c0 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/BlockColorCalculatorFactory.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/BlockColorCalculatorFactory.java @@ -123,13 +123,7 @@ public Color getBlockColor(BlockNeighborhood block, Color target) { } public Color getRedstoneColor(BlockNeighborhood block, Color target) { - String powerString = block.getBlockState().getProperties().get("power"); - - int power = 15; - if (powerString != null) { - power = Integer.parseInt(powerString); - } - + int power = block.getBlockState().getRedstonePower(); return target.set( (power + 5f) / 20f, 0f, 0f, 1f, true @@ -141,11 +135,11 @@ public Color getWaterAverageColor(BlockNeighborhood block, Color target) { int x, y, z, minX = - 2, - maxX = + 2, + maxX = 2, minY = - 1, - maxY = + 1, + maxY = 1, minZ = - 2, - maxZ = + 2; + maxZ = 2; Biome biome; for (x = minX; x <= maxX; x++) { @@ -165,11 +159,11 @@ public Color getFoliageAverageColor(BlockNeighborhood block, Color target) { int x, y, z, minX = - 2, - maxX = + 2, + maxX = 2, minY = - 1, - maxY = + 1, + maxY = 1, minZ = - 2, - maxZ = + 2; + maxZ = 2; Biome biome; for (y = minY; y <= maxY; y++) { @@ -194,11 +188,11 @@ public Color getGrassAverageColor(BlockNeighborhood block, Color target) { int x, y, z, minX = - 2, - maxX = + 2, + maxX = 2, minY = - 1, - maxY = + 1, + maxY = 1, minZ = - 2, - maxZ = + 2; + maxZ = 2; Biome biome; for (y = minY; y <= maxY; y++) { 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 63eff748..f39daaaa 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 @@ -54,6 +54,7 @@ public class BlockState extends Key { private final Property[] propertiesArray; private final boolean isAir, isWater, isWaterlogged; + private int liquidLevel = -1, redstonePower = -1; public BlockState(String value) { this(value, Collections.emptyMap()); @@ -80,6 +81,7 @@ public BlockState(String value, Map properties) { this.isWater = "minecraft:water".equals(this.getFormatted()); this.isWaterlogged = "true".equals(properties.get("waterlogged")); + } /** @@ -107,13 +109,42 @@ public boolean isWaterlogged() { return isWaterlogged; } + public int getLiquidLevel() { + if (liquidLevel == -1) { + try { + String levelString = properties.get("level"); + liquidLevel = levelString != null ? Integer.parseInt(levelString) : 0; + if (liquidLevel > 15) liquidLevel = 15; + if (liquidLevel < 0) liquidLevel = 0; + } catch (NumberFormatException ex) { + liquidLevel = 0; + } + } + return liquidLevel; + } + + public int getRedstonePower() { + if (redstonePower == -1) { + try { + String levelString = properties.get("power"); + redstonePower = levelString != null ? Integer.parseInt(levelString) : 0; + if (redstonePower > 15) redstonePower = 15; + if (redstonePower < 0) redstonePower = 0; + } catch (NumberFormatException ex) { + redstonePower = 15; + } + } + return redstonePower; + } + + @SuppressWarnings("StringEquality") @Override public boolean equals(Object obj) { if (this == obj) return true; if (!(obj instanceof BlockState)) return false; BlockState b = (BlockState) obj; - if (!Objects.equals(getFormatted(), b.getFormatted())) return false; + if (getFormatted() != b.getFormatted()) return false; return Arrays.equals(propertiesArray, b.propertiesArray); } diff --git a/implementations/spigot/src/main/java/de/bluecolored/bluemap/bukkit/BukkitCommandSource.java b/implementations/spigot/src/main/java/de/bluecolored/bluemap/bukkit/BukkitCommandSource.java index 0f5c80e2..ddb17799 100644 --- a/implementations/spigot/src/main/java/de/bluecolored/bluemap/bukkit/BukkitCommandSource.java +++ b/implementations/spigot/src/main/java/de/bluecolored/bluemap/bukkit/BukkitCommandSource.java @@ -26,8 +26,8 @@ import com.flowpowered.math.vector.Vector3d; import de.bluecolored.bluemap.common.plugin.Plugin; -import de.bluecolored.bluemap.common.serverinterface.CommandSource; import de.bluecolored.bluemap.common.plugin.text.Text; +import de.bluecolored.bluemap.common.serverinterface.CommandSource; import de.bluecolored.bluemap.core.world.World; import org.bukkit.Bukkit; import org.bukkit.Location;