Little improvements here and there

This commit is contained in:
Lukas Rieger (Blue) 2022-10-19 16:25:25 +02:00
parent c5a91431cd
commit c6019c722d
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
5 changed files with 52 additions and 35 deletions

View File

@ -110,8 +110,7 @@ public class LiquidModelBuilder {
(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 @@ public class LiquidModelBuilder {
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 @@ public class LiquidModelBuilder {
}
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();

View File

@ -35,8 +35,6 @@ import java.util.Map.Entry;
@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 class ChunkAnvil118 extends MCAChunk {
ListTag<CompoundTag> paletteTag = (ListTag<CompoundTag>) 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 class ChunkAnvil118 extends MCAChunk {
}
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<String, String> properties = new LinkedHashMap<>();
if (paletteEntry.containsKey("Properties")) {
CompoundTag propertiesTag = paletteEntry.getCompoundTag("Properties");
for (Entry<String, Tag<?>> property : propertiesTag) {

View File

@ -123,13 +123,7 @@ public class BlockColorCalculatorFactory {
}
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 class BlockColorCalculatorFactory {
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 class BlockColorCalculatorFactory {
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 class BlockColorCalculatorFactory {
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++) {

View File

@ -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 class BlockState extends Key {
this.isWater = "minecraft:water".equals(this.getFormatted());
this.isWaterlogged = "true".equals(properties.get("waterlogged"));
}
/**
@ -107,13 +109,42 @@ public class BlockState extends Key {
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);
}

View File

@ -26,8 +26,8 @@ package de.bluecolored.bluemap.bukkit;
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;