Skip to content

Commit 538f1f7

Browse files
committed
Add id:meta and biome debug info to debug command
1 parent 49ddaa7 commit 538f1f7

File tree

5 files changed

+67
-8
lines changed

5 files changed

+67
-8
lines changed

BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/BlockIdConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public BlockIdConfig(ConfigurationNode node, ConfigurationLoader<? extends Confi
6666

6767
BlockIDMeta idmeta = new BlockIDMeta(blockId, blockMeta);
6868
BlockState state = BlockState.fromString(value);
69-
69+
7070
if (blockId == 0) state = BlockState.AIR; //use the static field to increase render speed (== comparison)
7171

7272
mappings.put(idmeta, state);

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import net.querz.nbt.ListTag;
3636
import net.querz.nbt.mca.MCAUtil;
3737

38-
class ChunkAnvil112 extends Chunk {
38+
public class ChunkAnvil112 extends Chunk {
3939
private BlockIdMapper blockIdMapper;
4040
private BiomeMapper biomeIdMapper;
4141

@@ -84,6 +84,15 @@ public BlockState getBlockState(Vector3i pos) {
8484
return section.getBlockState(pos);
8585
}
8686

87+
public String getBlockIdMeta(Vector3i pos) {
88+
int sectionY = MCAUtil.blockToChunk(pos.getY());
89+
90+
Section section = this.sections[sectionY];
91+
if (section == null) return "0:0";
92+
93+
return section.getBlockIdMeta(pos);
94+
}
95+
8796
@Override
8897
public LightData getLightData(Vector3i pos) {
8998
int sectionY = MCAUtil.blockToChunk(pos.getY());
@@ -119,7 +128,7 @@ public Section(CompoundTag sectionData) {
119128
this.skyLight = sectionData.getByteArray("SkyLight");
120129
this.data = sectionData.getByteArray("Data");
121130
}
122-
131+
123132
public int getSectionY() {
124133
return sectionY;
125134
}
@@ -145,6 +154,25 @@ public BlockState getBlockState(Vector3i pos) {
145154
return blockState;
146155
}
147156

157+
public String getBlockIdMeta(Vector3i pos) {
158+
int x = pos.getX() & 0xF; // Math.floorMod(pos.getX(), 16)
159+
int y = pos.getY() & 0xF;
160+
int z = pos.getZ() & 0xF;
161+
int blockByteIndex = y * 256 + z * 16 + x;
162+
int blockHalfByteIndex = blockByteIndex >> 1; // blockByteIndex / 2
163+
boolean largeHalf = (blockByteIndex & 0x1) != 0; // (blockByteIndex % 2) == 0
164+
165+
int blockId = this.blocks[blockByteIndex] & 0xFF;
166+
167+
if (this.add.length > 0) {
168+
blockId = blockId | (getByteHalf(this.add[blockHalfByteIndex], largeHalf) << 8);
169+
}
170+
171+
int blockData = getByteHalf(this.data[blockHalfByteIndex], largeHalf);
172+
173+
return blockId + ":" + blockData;
174+
}
175+
148176
public LightData getLightData(Vector3i pos) {
149177
int x = pos.getX() & 0xF; // Math.floorMod(pos.getX(), 16)
150178
int y = pos.getY() & 0xF;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import net.querz.nbt.Tag;
4444
import net.querz.nbt.mca.MCAUtil;
4545

46-
class ChunkAnvil113 extends Chunk {
46+
public class ChunkAnvil113 extends Chunk {
4747
private BiomeMapper biomeIdMapper;
4848

4949
private boolean isGenerated;

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import com.flowpowered.math.vector.Vector3f;
2828
import com.flowpowered.math.vector.Vector4f;
29+
import com.google.common.base.MoreObjects;
2930

3031
import de.bluecolored.bluemap.core.util.ConfigUtils;
3132
import de.bluecolored.bluemap.core.util.MathUtils;
@@ -103,6 +104,17 @@ public static Biome create(String id, ConfigurationNode node) {
103104
return biome;
104105
}
105106

106-
107+
@Override
108+
public String toString() {
109+
return MoreObjects.toStringHelper(this)
110+
.add("id", getId())
111+
.add("ordinal", getOrdinal())
112+
.add("humidity", getHumidity())
113+
.add("temp", getTemp())
114+
.add("waterColor", getWaterColor())
115+
.add("overlayFoliageColor", getOverlayFoliageColor())
116+
.add("overlayGrassColor", getOverlayGrassColor())
117+
.toString();
118+
}
107119

108120
}

BlueMapSponge/src/main/java/de/bluecolored/bluemap/sponge/Commands.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.bluecolored.bluemap.sponge;
22

3+
import java.io.IOException;
34
import java.util.ArrayList;
45
import java.util.Collection;
56
import java.util.HashSet;
@@ -27,6 +28,9 @@
2728
import com.google.common.collect.Lists;
2829

2930
import de.bluecolored.bluemap.core.logger.Logger;
31+
import de.bluecolored.bluemap.core.mca.Chunk;
32+
import de.bluecolored.bluemap.core.mca.ChunkAnvil112;
33+
import de.bluecolored.bluemap.core.mca.MCAWorld;
3034
import de.bluecolored.bluemap.core.render.hires.HiresModelManager;
3135
import de.bluecolored.bluemap.core.world.Block;
3236
import de.bluecolored.bluemap.core.world.World;
@@ -51,9 +55,24 @@ public CommandSpec createRootCommand() {
5155
Block block = world.getBlock(loc.getBlockPosition());
5256
Block blockBelow = world.getBlock(loc.getBlockPosition().add(0, -1, 0));
5357

58+
String blockIdMeta = "";
59+
String blockBelowIdMeta = "";
60+
61+
if (world instanceof MCAWorld) {
62+
try {
63+
Chunk chunk = ((MCAWorld) world).getChunk(MCAWorld.blockToChunk(loc.getBlockPosition()));
64+
if (chunk instanceof ChunkAnvil112) {
65+
blockIdMeta = " (id:" + ((ChunkAnvil112) chunk).getBlockIdMeta(loc.getBlockPosition()) + ")";
66+
blockBelowIdMeta = " (id:" + ((ChunkAnvil112) chunk).getBlockIdMeta(loc.getBlockPosition().add(0, -1, 0)) + ")";
67+
}
68+
} catch (IOException ex) {
69+
Logger.global.logError("Failed to read chunk for debug!", ex);
70+
}
71+
}
72+
5473
source.sendMessages(Lists.newArrayList(
55-
Text.of("Block: " + block),
56-
Text.of("Block below: " + blockBelow)
74+
Text.of("Block: " + block + blockIdMeta),
75+
Text.of("Block below: " + blockBelow + blockBelowIdMeta)
5776
));
5877
}
5978

@@ -69,7 +88,7 @@ public CommandSpec createRootCommand() {
6988
.child(createPauseRenderCommand(), "pause")
7089
.child(createResumeRenderCommand(), "resume")
7190
.child(createRenderCommand(), "render")
72-
//.child(debugCommand, "debug")
91+
.child(debugCommand, "debug")
7392
.executor((source, args) -> {
7493
source.sendMessages(createStatusMessage());
7594
return CommandResult.success();

0 commit comments

Comments
 (0)