Add id:meta and biome debug info to debug command

This commit is contained in:
Blue (Lukas Rieger) 2020-01-07 18:19:35 +01:00
parent 49ddaa7c81
commit 538f1f7887
5 changed files with 67 additions and 8 deletions

View File

@ -66,7 +66,7 @@ public class BlockIdConfig implements BlockIdMapper {
BlockIDMeta idmeta = new BlockIDMeta(blockId, blockMeta);
BlockState state = BlockState.fromString(value);
if (blockId == 0) state = BlockState.AIR; //use the static field to increase render speed (== comparison)
mappings.put(idmeta, state);

View File

@ -35,7 +35,7 @@ import net.querz.nbt.CompoundTag;
import net.querz.nbt.ListTag;
import net.querz.nbt.mca.MCAUtil;
class ChunkAnvil112 extends Chunk {
public class ChunkAnvil112 extends Chunk {
private BlockIdMapper blockIdMapper;
private BiomeMapper biomeIdMapper;
@ -84,6 +84,15 @@ class ChunkAnvil112 extends Chunk {
return section.getBlockState(pos);
}
public String getBlockIdMeta(Vector3i pos) {
int sectionY = MCAUtil.blockToChunk(pos.getY());
Section section = this.sections[sectionY];
if (section == null) return "0:0";
return section.getBlockIdMeta(pos);
}
@Override
public LightData getLightData(Vector3i pos) {
int sectionY = MCAUtil.blockToChunk(pos.getY());
@ -119,7 +128,7 @@ class ChunkAnvil112 extends Chunk {
this.skyLight = sectionData.getByteArray("SkyLight");
this.data = sectionData.getByteArray("Data");
}
public int getSectionY() {
return sectionY;
}
@ -145,6 +154,25 @@ class ChunkAnvil112 extends Chunk {
return blockState;
}
public String getBlockIdMeta(Vector3i pos) {
int x = pos.getX() & 0xF; // Math.floorMod(pos.getX(), 16)
int y = pos.getY() & 0xF;
int z = pos.getZ() & 0xF;
int blockByteIndex = y * 256 + z * 16 + x;
int blockHalfByteIndex = blockByteIndex >> 1; // blockByteIndex / 2
boolean largeHalf = (blockByteIndex & 0x1) != 0; // (blockByteIndex % 2) == 0
int blockId = this.blocks[blockByteIndex] & 0xFF;
if (this.add.length > 0) {
blockId = blockId | (getByteHalf(this.add[blockHalfByteIndex], largeHalf) << 8);
}
int blockData = getByteHalf(this.data[blockHalfByteIndex], largeHalf);
return blockId + ":" + blockData;
}
public LightData getLightData(Vector3i pos) {
int x = pos.getX() & 0xF; // Math.floorMod(pos.getX(), 16)
int y = pos.getY() & 0xF;

View File

@ -43,7 +43,7 @@ import net.querz.nbt.StringTag;
import net.querz.nbt.Tag;
import net.querz.nbt.mca.MCAUtil;
class ChunkAnvil113 extends Chunk {
public class ChunkAnvil113 extends Chunk {
private BiomeMapper biomeIdMapper;
private boolean isGenerated;

View File

@ -26,6 +26,7 @@ package de.bluecolored.bluemap.core.world;
import com.flowpowered.math.vector.Vector3f;
import com.flowpowered.math.vector.Vector4f;
import com.google.common.base.MoreObjects;
import de.bluecolored.bluemap.core.util.ConfigUtils;
import de.bluecolored.bluemap.core.util.MathUtils;
@ -103,6 +104,17 @@ public class Biome {
return biome;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("id", getId())
.add("ordinal", getOrdinal())
.add("humidity", getHumidity())
.add("temp", getTemp())
.add("waterColor", getWaterColor())
.add("overlayFoliageColor", getOverlayFoliageColor())
.add("overlayGrassColor", getOverlayGrassColor())
.toString();
}
}

View File

@ -1,5 +1,6 @@
package de.bluecolored.bluemap.sponge;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@ -27,6 +28,9 @@ import com.flowpowered.math.vector.Vector3i;
import com.google.common.collect.Lists;
import de.bluecolored.bluemap.core.logger.Logger;
import de.bluecolored.bluemap.core.mca.Chunk;
import de.bluecolored.bluemap.core.mca.ChunkAnvil112;
import de.bluecolored.bluemap.core.mca.MCAWorld;
import de.bluecolored.bluemap.core.render.hires.HiresModelManager;
import de.bluecolored.bluemap.core.world.Block;
import de.bluecolored.bluemap.core.world.World;
@ -51,9 +55,24 @@ public class Commands {
Block block = world.getBlock(loc.getBlockPosition());
Block blockBelow = world.getBlock(loc.getBlockPosition().add(0, -1, 0));
String blockIdMeta = "";
String blockBelowIdMeta = "";
if (world instanceof MCAWorld) {
try {
Chunk chunk = ((MCAWorld) world).getChunk(MCAWorld.blockToChunk(loc.getBlockPosition()));
if (chunk instanceof ChunkAnvil112) {
blockIdMeta = " (id:" + ((ChunkAnvil112) chunk).getBlockIdMeta(loc.getBlockPosition()) + ")";
blockBelowIdMeta = " (id:" + ((ChunkAnvil112) chunk).getBlockIdMeta(loc.getBlockPosition().add(0, -1, 0)) + ")";
}
} catch (IOException ex) {
Logger.global.logError("Failed to read chunk for debug!", ex);
}
}
source.sendMessages(Lists.newArrayList(
Text.of("Block: " + block),
Text.of("Block below: " + blockBelow)
Text.of("Block: " + block + blockIdMeta),
Text.of("Block below: " + blockBelow + blockBelowIdMeta)
));
}
@ -69,7 +88,7 @@ public class Commands {
.child(createPauseRenderCommand(), "pause")
.child(createResumeRenderCommand(), "resume")
.child(createRenderCommand(), "render")
//.child(debugCommand, "debug")
.child(debugCommand, "debug")
.executor((source, args) -> {
source.sendMessages(createStatusMessage());
return CommandResult.success();