Search in sources :

Example 11 with CompoundTag

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();
        }
    }
}
Also used : NBTInputStream(org.jnbt.NBTInputStream) Painting(org.pepsoft.minecraft.Painting) CompoundTag(org.jnbt.CompoundTag) ChunkImpl2(org.pepsoft.minecraft.ChunkImpl2) IOException(java.io.IOException) File(java.io.File) RegionFile(org.pepsoft.minecraft.RegionFile) RegionFile(org.pepsoft.minecraft.RegionFile) NBTInputStream(org.jnbt.NBTInputStream) File(java.io.File) RegionFile(org.pepsoft.minecraft.RegionFile) CompoundTag(org.jnbt.CompoundTag) ChunkImpl2(org.pepsoft.minecraft.ChunkImpl2) Painting(org.pepsoft.minecraft.Painting)

Example 12 with CompoundTag

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));
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) BitSet(java.util.BitSet) NBTInputStream(org.jnbt.NBTInputStream) CompoundTag(org.jnbt.CompoundTag) Tag(org.jnbt.Tag) File(java.io.File)

Aggregations

CompoundTag (org.jnbt.CompoundTag)12 NBTInputStream (org.jnbt.NBTInputStream)12 Tag (org.jnbt.Tag)7 File (java.io.File)5 Pattern (java.util.regex.Pattern)4 IOException (java.io.IOException)3 GZIPInputStream (java.util.zip.GZIPInputStream)3 InputStream (java.io.InputStream)2 NBTOutputStream (org.jnbt.NBTOutputStream)2 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 Matcher (java.util.regex.Matcher)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 DoubleTag (org.jnbt.DoubleTag)1 IntTag (org.jnbt.IntTag)1 ListTag (org.jnbt.ListTag)1 ShortTag (org.jnbt.ShortTag)1 ChunkImpl2 (org.pepsoft.minecraft.ChunkImpl2)1