private static List<Chunk> loadChunks(String arg) throws Exception { File region = new File(arg, "region"); final List<Chunk> chunks = new ArrayList<>(); for (File file : region.listFiles()) { if (file.getName().endsWith(".mca")) { final Point offset = parseMcaFileName(file.getName()); try (RegionFile rf = new RegionFile(file)) { for (int z = 0; z < 32; z++) { for (int x = 0; x < 32; x++) { if (rf.hasChunk(x, z)) { try (NBTStreamReader sr = rf.getChunk(x, z)) { final int xx = x; final int zz = z; new NBTWalker(sr) { boolean inSections; byte y; byte[] blocks; @Override public boolean value(String name, byte value) throws Exception { if ("Y".equals(name)) { y = value; } return super.value(name, value); } @Override public boolean value(String name, byte[] value) throws Exception { if ("Blocks".equals(name)) { blocks = value; } return true; } @Override public boolean list(String name, int length) throws Exception { inSections = "Sections".equals(name); super.list(name, length); return !inSections; } @Override public boolean compound(String name) throws Exception { if (!super.compound(name)) { return false; } if (inSections) { chunks.add( new Chunk( new Vector(offset.getX() * 32 + xx, y, offset.getY() * 32 + zz), blocks)); } return true; } }; } } } } } } } return chunks; }