use of org.jnbt.CompoundTag in project WorldPainter by Captain-Chaos.
the class DumpEntities method main.
public static void main(String[] args) throws IOException {
File worldDir = new File(args[0]);
File[] regionFiles = new File(worldDir, "region").listFiles();
for (File file : regionFiles) {
RegionFile regionFile = new RegionFile(file);
try {
for (int x = 0; x < 32; x++) {
for (int z = 0; z < 32; z++) {
if (regionFile.containsChunk(x, z)) {
CompoundTag tag;
try (NBTInputStream in = new NBTInputStream(regionFile.getChunkDataInputStream(x, z))) {
tag = (CompoundTag) in.readTag();
}
ChunkImpl2 chunk = new ChunkImpl2(tag, 256);
/*&& (((Painting) entity).getTileX() == 40) && (((Painting) entity).getTileZ() == 31)*/
chunk.getEntities().stream().filter(entity -> (entity instanceof Painting)).forEach(System.out::println);
}
}
}
} finally {
regionFile.close();
}
}
}
use of org.jnbt.CompoundTag in project WorldPainter by Captain-Chaos.
the class RegressionIT method verifyJavaDimension.
protected void verifyJavaDimension(File worldDir, Dimension dimension, int... expectedBlocks) throws IOException {
World2 world = dimension.getWorld();
logger.info("Verifying dimension {} of map {}", dimension.getName(), world.getName());
boolean checkBounds;
Rectangle expectedBounds = null;
if (!dimension.containsOneOf(NotPresent.INSTANCE)) {
checkBounds = true;
int lowestTileX, highestTileX, lowestTileY, highestTileY;
if (dimension.getWorld().getTilesToExport() != null) {
lowestTileX = Integer.MAX_VALUE;
highestTileX = Integer.MIN_VALUE;
lowestTileY = Integer.MAX_VALUE;
highestTileY = Integer.MIN_VALUE;
for (Point tile : dimension.getWorld().getTilesToExport()) {
if (tile.x < lowestTileX) {
lowestTileX = tile.x;
}
if (tile.x > highestTileX) {
highestTileX = tile.x;
}
if (tile.y < lowestTileY) {
lowestTileY = tile.y;
}
if (tile.y > highestTileY) {
highestTileY = tile.y;
}
}
} else {
lowestTileX = dimension.getLowestX();
highestTileX = dimension.getHighestX();
lowestTileY = dimension.getLowestY();
highestTileY = dimension.getHighestY();
}
int expectedLowestChunkX = lowestTileX << 3;
int expectedHighestChunkX = ((highestTileX + 1) << 3) - 1;
int expectedLowestChunkZ = lowestTileY << 3;
int expectedHighestChunkZ = ((highestTileY + 1) << 3) - 1;
expectedBounds = new Rectangle(expectedLowestChunkX, expectedLowestChunkZ, expectedHighestChunkX - expectedLowestChunkX + 1, expectedHighestChunkZ - expectedLowestChunkZ + 1);
} else {
checkBounds = false;
logger.warn("Skipping bounds check for dimension which contains the NotReady layer");
}
File regionDir;
switch(dimension.getDim()) {
case DIM_NORMAL:
regionDir = new File(worldDir, "region");
break;
case DIM_NETHER:
regionDir = new File(worldDir, "DIM-1/region");
break;
case DIM_END:
regionDir = new File(worldDir, "DIM1/region");
break;
default:
throw new IllegalArgumentException();
}
Platform platform = world.getPlatform();
int maxHeight = dimension.getMaxHeight();
Pattern regionFilePattern = platform.equals(DefaultPlugin.JAVA_MCREGION) ? Pattern.compile("r\\.(-?\\d+)\\.(-?\\d+)\\.mcr") : Pattern.compile("r\\.(-?\\d+)\\.(-?\\d+)\\.mca");
int lowestChunkX = Integer.MAX_VALUE, highestChunkX = Integer.MIN_VALUE;
int lowestChunkZ = Integer.MAX_VALUE, highestChunkZ = Integer.MIN_VALUE;
BitSet blockTypes = new BitSet(256);
for (File file : regionDir.listFiles()) {
Matcher matcher = regionFilePattern.matcher(file.getName());
if (matcher.matches()) {
int regionX = Integer.parseInt(matcher.group(1));
int regionZ = Integer.parseInt(matcher.group(2));
try (RegionFile regionFile = new RegionFile(file, true)) {
for (int chunkX = 0; chunkX < 32; chunkX++) {
for (int chunkZ = 0; chunkZ < 32; chunkZ++) {
if (regionFile.containsChunk(chunkX, chunkZ)) {
int absChunkX = (regionX << 5) + chunkX;
int absChunkZ = (regionZ << 5) + chunkZ;
if (absChunkX < lowestChunkX) {
lowestChunkX = absChunkX;
}
if (absChunkX > highestChunkX) {
highestChunkX = absChunkX;
}
if (absChunkZ < lowestChunkZ) {
lowestChunkZ = absChunkZ;
}
if (absChunkZ > highestChunkZ) {
highestChunkZ = absChunkZ;
}
Chunk chunk;
try (NBTInputStream in = new NBTInputStream(regionFile.getChunkDataInputStream(chunkX, chunkZ))) {
Tag tag = in.readTag();
chunk = platform.equals(DefaultPlugin.JAVA_MCREGION) ? new ChunkImpl((CompoundTag) tag, maxHeight, true) : new ChunkImpl2((CompoundTag) tag, maxHeight, true);
}
// all block types present
for (int x = 0; x < 16; x++) {
for (int y = 0; y < maxHeight; y++) {
for (int z = 0; z < 16; z++) {
blockTypes.set(chunk.getBlockType(x, y, z));
}
}
}
}
}
}
}
}
}
if (checkBounds) {
assertEquals(expectedBounds, new Rectangle(lowestChunkX, lowestChunkZ, highestChunkX - lowestChunkX + 1, highestChunkZ - lowestChunkZ + 1));
}
// types and layers used
for (int expectedBlock : expectedBlocks) {
assertTrue("expected block type " + Block.BLOCKS[expectedBlock].name + " missing", blockTypes.get(expectedBlock));
}
}
Aggregations