Skip to content

Commit c6019c7

Browse files
committed
Little improvements here and there
1 parent c5a9143 commit c6019c7

File tree

5 files changed

+52
-35
lines changed

5 files changed

+52
-35
lines changed

BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/LiquidModelBuilder.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ private void build() {
110110
(renderSettings.isCaveDetectionUsesBlockLight() ? block.getBlockLightLevel() : block.getSunLightLevel()) == 0f
111111
) return;
112112

113-
int level = getLiquidLevel(blockState);
114-
113+
int level = blockState.getLiquidLevel();
115114
if (level < 8 && !(level == 0 && isSameLiquid(block.getNeighborBlock(0, 1, 0)))){
116115
corners[4].y = getLiquidCornerHeight(-1, -1);
117116
corners[5].y = getLiquidCornerHeight(-1, 0);
@@ -196,7 +195,7 @@ private float getLiquidCornerHeight(int x, int z){
196195
neighbor = block.getNeighborBlock(ix, 0, iz);
197196
neighborBlockState = neighbor.getBlockState();
198197
if (isSameLiquid(neighbor)){
199-
if (getLiquidLevel(neighborBlockState) == 0) return 14f;
198+
if (neighborBlockState.getLiquidLevel() == 0) return 14f;
200199

201200
sumHeight += getLiquidBaseHeight(neighborBlockState);
202201
count++;
@@ -216,24 +215,20 @@ else if (!isLiquidBlockingBlock(neighborBlockState)){
216215
}
217216

218217
private boolean isLiquidBlockingBlock(BlockState blockState){
219-
return !blockState.equals(BlockState.AIR);
218+
return !blockState.isAir();
220219
}
221220

221+
@SuppressWarnings("StringEquality")
222222
private boolean isSameLiquid(ExtendedBlock<?> block){
223-
if (block.getBlockState().getFormatted().equals(this.blockState.getFormatted())) return true;
223+
if (block.getBlockState().getFormatted() == this.blockState.getFormatted()) return true;
224224
return this.blockState.isWater() && (block.getBlockState().isWaterlogged() || block.getProperties().isAlwaysWaterlogged());
225225
}
226226

227227
private float getLiquidBaseHeight(BlockState block){
228-
int level = getLiquidLevel(block);
228+
int level = block.getLiquidLevel();
229229
return level >= 8 ? 16f : 14f - level * 1.9f;
230230
}
231231

232-
private int getLiquidLevel(BlockState block){
233-
String levelString = block.getProperties().get("level");
234-
return levelString != null ? Integer.parseInt(levelString) : 0;
235-
}
236-
237232
private final MatrixM3f uvTransform = new MatrixM3f();
238233
private boolean createElementFace(Direction faceDir, VectorM3f c0, VectorM3f c1, VectorM3f c2, VectorM3f c3, Color color, int stillTextureId, int flowTextureId) {
239234
Vector3i faceDirVector = faceDir.toVector();

BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil118.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535

3636
@SuppressWarnings("FieldMayBeFinal")
3737
public class ChunkAnvil118 extends MCAChunk {
38-
private static final String AIR_ID = "minecraft:air";
39-
4038
private boolean isGenerated;
4139
private boolean hasLight;
4240

@@ -74,7 +72,7 @@ public ChunkAnvil118(MCAWorld world, CompoundTag chunkTag) {
7472
ListTag<CompoundTag> paletteTag = (ListTag<CompoundTag>) blockStatesTag.getListTag("palette");
7573
if (paletteTag == null) continue;
7674
if (paletteTag.size() == 0) continue;
77-
if (paletteTag.size() == 1 && AIR_ID.equals(paletteTag.get(0).getString("Name"))) continue;
75+
if (paletteTag.size() == 1 && BlockState.AIR.getFormatted().equals(paletteTag.get(0).getString("Name"))) continue;
7876

7977
Section section = new Section(sectionTag);
8078
int y = section.getSectionY();
@@ -214,11 +212,10 @@ public Section(CompoundTag sectionData) {
214212
}
215213

216214
private BlockState readBlockStatePaletteEntry(CompoundTag paletteEntry) {
217-
String id = paletteEntry.getString("Name"); //shortcut to save time and memory
218-
if (AIR_ID.equals(id)) return BlockState.AIR;
215+
String id = paletteEntry.getString("Name");
216+
if (BlockState.AIR.getFormatted().equals(id)) return BlockState.AIR; //shortcut to save time and memory
219217

220218
Map<String, String> properties = new LinkedHashMap<>();
221-
222219
if (paletteEntry.containsKey("Properties")) {
223220
CompoundTag propertiesTag = paletteEntry.getCompoundTag("Properties");
224221
for (Entry<String, Tag<?>> property : propertiesTag) {

BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/BlockColorCalculatorFactory.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,7 @@ public Color getBlockColor(BlockNeighborhood<?> block, Color target) {
123123
}
124124

125125
public Color getRedstoneColor(BlockNeighborhood<?> block, Color target) {
126-
String powerString = block.getBlockState().getProperties().get("power");
127-
128-
int power = 15;
129-
if (powerString != null) {
130-
power = Integer.parseInt(powerString);
131-
}
132-
126+
int power = block.getBlockState().getRedstonePower();
133127
return target.set(
134128
(power + 5f) / 20f, 0f, 0f,
135129
1f, true
@@ -141,11 +135,11 @@ public Color getWaterAverageColor(BlockNeighborhood<?> block, Color target) {
141135

142136
int x, y, z,
143137
minX = - 2,
144-
maxX = + 2,
138+
maxX = 2,
145139
minY = - 1,
146-
maxY = + 1,
140+
maxY = 1,
147141
minZ = - 2,
148-
maxZ = + 2;
142+
maxZ = 2;
149143

150144
Biome biome;
151145
for (x = minX; x <= maxX; x++) {
@@ -165,11 +159,11 @@ public Color getFoliageAverageColor(BlockNeighborhood<?> block, Color target) {
165159

166160
int x, y, z,
167161
minX = - 2,
168-
maxX = + 2,
162+
maxX = 2,
169163
minY = - 1,
170-
maxY = + 1,
164+
maxY = 1,
171165
minZ = - 2,
172-
maxZ = + 2;
166+
maxZ = 2;
173167

174168
Biome biome;
175169
for (y = minY; y <= maxY; y++) {
@@ -194,11 +188,11 @@ public Color getGrassAverageColor(BlockNeighborhood<?> block, Color target) {
194188

195189
int x, y, z,
196190
minX = - 2,
197-
maxX = + 2,
191+
maxX = 2,
198192
minY = - 1,
199-
maxY = + 1,
193+
maxY = 1,
200194
minZ = - 2,
201-
maxZ = + 2;
195+
maxZ = 2;
202196

203197
Biome biome;
204198
for (y = minY; y <= maxY; y++) {

BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/BlockState.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class BlockState extends Key {
5454
private final Property[] propertiesArray;
5555

5656
private final boolean isAir, isWater, isWaterlogged;
57+
private int liquidLevel = -1, redstonePower = -1;
5758

5859
public BlockState(String value) {
5960
this(value, Collections.emptyMap());
@@ -80,6 +81,7 @@ public BlockState(String value, Map<String, String> properties) {
8081

8182
this.isWater = "minecraft:water".equals(this.getFormatted());
8283
this.isWaterlogged = "true".equals(properties.get("waterlogged"));
84+
8385
}
8486

8587
/**
@@ -107,13 +109,42 @@ public boolean isWaterlogged() {
107109
return isWaterlogged;
108110
}
109111

112+
public int getLiquidLevel() {
113+
if (liquidLevel == -1) {
114+
try {
115+
String levelString = properties.get("level");
116+
liquidLevel = levelString != null ? Integer.parseInt(levelString) : 0;
117+
if (liquidLevel > 15) liquidLevel = 15;
118+
if (liquidLevel < 0) liquidLevel = 0;
119+
} catch (NumberFormatException ex) {
120+
liquidLevel = 0;
121+
}
122+
}
123+
return liquidLevel;
124+
}
125+
126+
public int getRedstonePower() {
127+
if (redstonePower == -1) {
128+
try {
129+
String levelString = properties.get("power");
130+
redstonePower = levelString != null ? Integer.parseInt(levelString) : 0;
131+
if (redstonePower > 15) redstonePower = 15;
132+
if (redstonePower < 0) redstonePower = 0;
133+
} catch (NumberFormatException ex) {
134+
redstonePower = 15;
135+
}
136+
}
137+
return redstonePower;
138+
}
139+
140+
@SuppressWarnings("StringEquality")
110141
@Override
111142
public boolean equals(Object obj) {
112143
if (this == obj) return true;
113144

114145
if (!(obj instanceof BlockState)) return false;
115146
BlockState b = (BlockState) obj;
116-
if (!Objects.equals(getFormatted(), b.getFormatted())) return false;
147+
if (getFormatted() != b.getFormatted()) return false;
117148
return Arrays.equals(propertiesArray, b.propertiesArray);
118149
}
119150

implementations/spigot/src/main/java/de/bluecolored/bluemap/bukkit/BukkitCommandSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727
import com.flowpowered.math.vector.Vector3d;
2828
import de.bluecolored.bluemap.common.plugin.Plugin;
29-
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
3029
import de.bluecolored.bluemap.common.plugin.text.Text;
30+
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
3131
import de.bluecolored.bluemap.core.world.World;
3232
import org.bukkit.Bukkit;
3333
import org.bukkit.Location;

0 commit comments

Comments
 (0)