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 @@ private void build() {
(renderSettings.isCaveDetectionUsesBlockLight() ? block.getBlockLightLevel() : block.getSunLightLevel()) == 0f (renderSettings.isCaveDetectionUsesBlockLight() ? block.getBlockLightLevel() : block.getSunLightLevel()) == 0f
) return; ) return;
int level = getLiquidLevel(blockState); int level = blockState.getLiquidLevel();
if (level < 8 && !(level == 0 && isSameLiquid(block.getNeighborBlock(0, 1, 0)))){ if (level < 8 && !(level == 0 && isSameLiquid(block.getNeighborBlock(0, 1, 0)))){
corners[4].y = getLiquidCornerHeight(-1, -1); corners[4].y = getLiquidCornerHeight(-1, -1);
corners[5].y = getLiquidCornerHeight(-1, 0); corners[5].y = getLiquidCornerHeight(-1, 0);
@ -196,7 +195,7 @@ private float getLiquidCornerHeight(int x, int z){
neighbor = block.getNeighborBlock(ix, 0, iz); neighbor = block.getNeighborBlock(ix, 0, iz);
neighborBlockState = neighbor.getBlockState(); neighborBlockState = neighbor.getBlockState();
if (isSameLiquid(neighbor)){ if (isSameLiquid(neighbor)){
if (getLiquidLevel(neighborBlockState) == 0) return 14f; if (neighborBlockState.getLiquidLevel() == 0) return 14f;
sumHeight += getLiquidBaseHeight(neighborBlockState); sumHeight += getLiquidBaseHeight(neighborBlockState);
count++; count++;
@ -216,24 +215,20 @@ else if (!isLiquidBlockingBlock(neighborBlockState)){
} }
private boolean isLiquidBlockingBlock(BlockState blockState){ private boolean isLiquidBlockingBlock(BlockState blockState){
return !blockState.equals(BlockState.AIR); return !blockState.isAir();
} }
@SuppressWarnings("StringEquality")
private boolean isSameLiquid(ExtendedBlock<?> block){ 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()); return this.blockState.isWater() && (block.getBlockState().isWaterlogged() || block.getProperties().isAlwaysWaterlogged());
} }
private float getLiquidBaseHeight(BlockState block){ private float getLiquidBaseHeight(BlockState block){
int level = getLiquidLevel(block); int level = block.getLiquidLevel();
return level >= 8 ? 16f : 14f - level * 1.9f; 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 final MatrixM3f uvTransform = new MatrixM3f();
private boolean createElementFace(Direction faceDir, VectorM3f c0, VectorM3f c1, VectorM3f c2, VectorM3f c3, Color color, int stillTextureId, int flowTextureId) { private boolean createElementFace(Direction faceDir, VectorM3f c0, VectorM3f c1, VectorM3f c2, VectorM3f c3, Color color, int stillTextureId, int flowTextureId) {
Vector3i faceDirVector = faceDir.toVector(); Vector3i faceDirVector = faceDir.toVector();

View File

@ -35,8 +35,6 @@
@SuppressWarnings("FieldMayBeFinal") @SuppressWarnings("FieldMayBeFinal")
public class ChunkAnvil118 extends MCAChunk { public class ChunkAnvil118 extends MCAChunk {
private static final String AIR_ID = "minecraft:air";
private boolean isGenerated; private boolean isGenerated;
private boolean hasLight; private boolean hasLight;
@ -74,7 +72,7 @@ public ChunkAnvil118(MCAWorld world, CompoundTag chunkTag) {
ListTag<CompoundTag> paletteTag = (ListTag<CompoundTag>) blockStatesTag.getListTag("palette"); ListTag<CompoundTag> paletteTag = (ListTag<CompoundTag>) blockStatesTag.getListTag("palette");
if (paletteTag == null) continue; if (paletteTag == null) continue;
if (paletteTag.size() == 0) 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); Section section = new Section(sectionTag);
int y = section.getSectionY(); int y = section.getSectionY();
@ -214,11 +212,10 @@ public Section(CompoundTag sectionData) {
} }
private BlockState readBlockStatePaletteEntry(CompoundTag paletteEntry) { private BlockState readBlockStatePaletteEntry(CompoundTag paletteEntry) {
String id = paletteEntry.getString("Name"); //shortcut to save time and memory String id = paletteEntry.getString("Name");
if (AIR_ID.equals(id)) return BlockState.AIR; if (BlockState.AIR.getFormatted().equals(id)) return BlockState.AIR; //shortcut to save time and memory
Map<String, String> properties = new LinkedHashMap<>(); Map<String, String> properties = new LinkedHashMap<>();
if (paletteEntry.containsKey("Properties")) { if (paletteEntry.containsKey("Properties")) {
CompoundTag propertiesTag = paletteEntry.getCompoundTag("Properties"); CompoundTag propertiesTag = paletteEntry.getCompoundTag("Properties");
for (Entry<String, Tag<?>> property : propertiesTag) { for (Entry<String, Tag<?>> property : propertiesTag) {

View File

@ -123,13 +123,7 @@ public Color getBlockColor(BlockNeighborhood<?> block, Color target) {
} }
public Color getRedstoneColor(BlockNeighborhood<?> block, Color target) { public Color getRedstoneColor(BlockNeighborhood<?> block, Color target) {
String powerString = block.getBlockState().getProperties().get("power"); int power = block.getBlockState().getRedstonePower();
int power = 15;
if (powerString != null) {
power = Integer.parseInt(powerString);
}
return target.set( return target.set(
(power + 5f) / 20f, 0f, 0f, (power + 5f) / 20f, 0f, 0f,
1f, true 1f, true
@ -141,11 +135,11 @@ public Color getWaterAverageColor(BlockNeighborhood<?> block, Color target) {
int x, y, z, int x, y, z,
minX = - 2, minX = - 2,
maxX = + 2, maxX = 2,
minY = - 1, minY = - 1,
maxY = + 1, maxY = 1,
minZ = - 2, minZ = - 2,
maxZ = + 2; maxZ = 2;
Biome biome; Biome biome;
for (x = minX; x <= maxX; x++) { for (x = minX; x <= maxX; x++) {
@ -165,11 +159,11 @@ public Color getFoliageAverageColor(BlockNeighborhood<?> block, Color target) {
int x, y, z, int x, y, z,
minX = - 2, minX = - 2,
maxX = + 2, maxX = 2,
minY = - 1, minY = - 1,
maxY = + 1, maxY = 1,
minZ = - 2, minZ = - 2,
maxZ = + 2; maxZ = 2;
Biome biome; Biome biome;
for (y = minY; y <= maxY; y++) { for (y = minY; y <= maxY; y++) {
@ -194,11 +188,11 @@ public Color getGrassAverageColor(BlockNeighborhood<?> block, Color target) {
int x, y, z, int x, y, z,
minX = - 2, minX = - 2,
maxX = + 2, maxX = 2,
minY = - 1, minY = - 1,
maxY = + 1, maxY = 1,
minZ = - 2, minZ = - 2,
maxZ = + 2; maxZ = 2;
Biome biome; Biome biome;
for (y = minY; y <= maxY; y++) { for (y = minY; y <= maxY; y++) {

View File

@ -54,6 +54,7 @@ public class BlockState extends Key {
private final Property[] propertiesArray; private final Property[] propertiesArray;
private final boolean isAir, isWater, isWaterlogged; private final boolean isAir, isWater, isWaterlogged;
private int liquidLevel = -1, redstonePower = -1;
public BlockState(String value) { public BlockState(String value) {
this(value, Collections.emptyMap()); this(value, Collections.emptyMap());
@ -80,6 +81,7 @@ public BlockState(String value, Map<String, String> properties) {
this.isWater = "minecraft:water".equals(this.getFormatted()); this.isWater = "minecraft:water".equals(this.getFormatted());
this.isWaterlogged = "true".equals(properties.get("waterlogged")); this.isWaterlogged = "true".equals(properties.get("waterlogged"));
} }
/** /**
@ -107,13 +109,42 @@ public boolean isWaterlogged() {
return 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 @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) return true; if (this == obj) return true;
if (!(obj instanceof BlockState)) return false; if (!(obj instanceof BlockState)) return false;
BlockState b = (BlockState) obj; BlockState b = (BlockState) obj;
if (!Objects.equals(getFormatted(), b.getFormatted())) return false; if (getFormatted() != b.getFormatted()) return false;
return Arrays.equals(propertiesArray, b.propertiesArray); return Arrays.equals(propertiesArray, b.propertiesArray);
} }

View File

@ -26,8 +26,8 @@
import com.flowpowered.math.vector.Vector3d; import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.common.plugin.Plugin; 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.plugin.text.Text;
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
import de.bluecolored.bluemap.core.world.World; import de.bluecolored.bluemap.core.world.World;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;