private void convertRegions(File baseFolder, ArrayList<File> regionFiles, BiomeSource biomeSource, int currentCount, int totalCount, ProgressListener progress) { for (File regionFile : regionFiles) { convertRegion(baseFolder, regionFile, biomeSource, currentCount, totalCount, progress); currentCount++; int percent = (int) Math.round(100.0d * (double) currentCount / (double) totalCount); progress.progressStagePercentage(percent); } }
private void convertRegion(File baseFolder, File regionFile, BiomeSource biomeSource, int currentCount, int totalCount, ProgressListener progress) { try { String name = regionFile.getName(); RegionFile regionSource = new RegionFile(regionFile); RegionFile regionDest = new RegionFile(new File(baseFolder, name.substring(0, name.length() - RegionFile.MCREGION_EXTENSION.length()) + RegionFile.ANVIL_EXTENSION)); for (int x = 0; x < 32; x++) { for (int z = 0; z < 32; z++) { if (regionSource.hasChunk(x, z) && !regionDest.hasChunk(x, z)) { DataInputStream regionChunkInputStream = regionSource.getChunkDataInputStream(x, z); if (regionChunkInputStream == null) { System.out.println("Failed to fetch input stream"); continue; } CompoundTag chunkData = NbtIo.read(regionChunkInputStream); regionChunkInputStream.close(); CompoundTag compound = chunkData.getCompound("Level"); { OldLevelChunk oldChunk = OldChunkStorage.load(compound); CompoundTag tag = new CompoundTag(); CompoundTag levelData = new CompoundTag(); tag.put("Level", levelData); OldChunkStorage.convertToAnvilFormat(oldChunk, levelData, biomeSource); DataOutputStream chunkDataOutputStream = regionDest.getChunkDataOutputStream(x, z); NbtIo.write(tag, chunkDataOutputStream); chunkDataOutputStream.close(); } } } int basePercent = (int) Math.round(100.0d * (double) (currentCount * 1024) / (double) (totalCount * 1024)); int newPercent = (int) Math.round(100.0d * (double) ((x + 1) * 32 + currentCount * 1024) / (double) (totalCount * 1024)); if (newPercent > basePercent) { progress.progressStagePercentage(newPercent); } } regionSource.close(); regionDest.close(); } catch (IOException e) { e.printStackTrace(); } }