diff --git a/README.md b/README.md index 6b33428..8f0c6f5 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Alternatively, to explicitly specify a version from the command line and skip th ### Version compatibility -MCResourceAnalyzer 1.1.4 can analyze worlds generated with any version of Minecraft: Java Edition between Indev 0.31 20100122 and 1.18. +MCResourceAnalyzer 1.1.5 can analyze worlds generated with any version of Minecraft: Java Edition between Indev 0.31 20100122 and 1.18. Note that Indev worlds with the `Long` and `Deep` world shapes are not supported. diff --git a/pom.xml b/pom.xml index 44713cc..456e83c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ io.github.meeples10.mcresourceanalyzer mc-resource-analyzer - 1.1.4 + 1.1.5 jar diff --git a/src/main/java/io/github/meeples10/mcresourceanalyzer/Main.java b/src/main/java/io/github/meeples10/mcresourceanalyzer/Main.java index d47af19..27384a1 100644 --- a/src/main/java/io/github/meeples10/mcresourceanalyzer/Main.java +++ b/src/main/java/io/github/meeples10/mcresourceanalyzer/Main.java @@ -106,7 +106,7 @@ public static void main(String[] args) { Object returnedVersion = JOptionPane.showInputDialog(null, "Select the format in which the region files were saved:", "Select Version", JOptionPane.PLAIN_MESSAGE, null, RegionAnalyzer.Version.values(), - RegionAnalyzer.Version.ANVIL_2021); + RegionAnalyzer.Version.values()[0]); if(!(returnedVersion instanceof RegionAnalyzer.Version)) System.exit(0); selectedVersion = (RegionAnalyzer.Version) returnedVersion; } @@ -117,7 +117,8 @@ public static void main(String[] args) { System.exit(1); return; } - if(analyzer == null) analyzer = new RegionAnalyzerAnvil2021(); + if(analyzer == null) analyzer = new RegionAnalyzerAnvil118(); + analyzer.setVersion(selectedVersion); if(inputOverride) { if(inputFile.isDirectory() != selectedVersion.usesDirectory()) { System.err.println("Input must be a " + (selectedVersion.usesDirectory() ? "directory" : "file") + ": " @@ -125,7 +126,7 @@ public static void main(String[] args) { System.exit(1); } } - analyzer.analyze(inputFile); + analyzer.run(inputFile); System.out.println("Completed after " + millisToHMS(System.currentTimeMillis() - analyzer.getStartTime())); } diff --git a/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzer.java b/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzer.java index 71a1e11..3b733bb 100644 --- a/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzer.java +++ b/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzer.java @@ -1,20 +1,104 @@ package io.github.meeples10.mcresourceanalyzer; import java.io.File; +import java.io.IOException; +import java.util.Comparator; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; +import java.util.stream.Collectors; public abstract class RegionAnalyzer { + private Version version; public long chunkCount = 0; public Map blockCounter = new HashMap(); public Map> heightCounter = new HashMap>(); private long firstStartTime; + public long endTime; public RegionAnalyzer() { firstStartTime = System.currentTimeMillis(); } - public abstract void analyze(File regionDir); + public void setVersion(Version version) { + this.version = version; + } + + public void run(File input) { + analyze(input); + + long totalBlocks = 0L; + for(String key : blockCounter.keySet()) { + totalBlocks += blockCounter.get(key); + } + System.out.println("--------------------------------\n" + blockCounter.size() + " unique blocks\n" + totalBlocks + + " blocks total\n--------------------------------"); + + System.out.print("Sorting data... "); + heightCounter = heightCounter.entrySet().stream().sorted(Map.Entry.comparingByKey(new Comparator() { + @Override + public int compare(String arg0, String arg1) { + return Long.compare(blockCounter.get(arg1), blockCounter.get(arg0)); + } + })).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); + System.out.println("Done"); + + double totalExcludingAir = (double) (totalBlocks - (blockCounter.containsKey("0") ? blockCounter.get("0") : 0) + - (blockCounter.containsKey("minecraft:air") ? blockCounter.get("minecraft:air") : 0) + - (blockCounter.containsKey("minecraft:cave_air") ? blockCounter.get("minecraft:cave_air") : 0)); + System.out.print("Generating CSV... "); + String data = "id,"; + int minY = getMinimumY(); + int maxY = getMaximumY(); + for(int i = minY; i <= maxY; i++) { + data += i + ","; + } + data += "total,percent_of_total,percent_excluding_air\n"; + int digits = String.valueOf(blockCounter.size()).length(); + String completionFormat = "[%0" + digits + "d/%0" + digits + "d]"; + int keyIndex = 0; + for(String key : heightCounter.keySet()) { + keyIndex += 1; + System.out.print("\rGenerating CSV... " + String.format(completionFormat, keyIndex, blockCounter.size())); + data += key + ","; + for(int i = minY; i <= maxY; i++) { + if(!heightCounter.get(key).containsKey(i)) { + data += "0,"; + } else { + data += heightCounter.get(key).get(i) + ","; + } + } + data += blockCounter.get(key) + "," + + Main.DECIMAL_FORMAT.format(((double) blockCounter.get(key) / (double) totalBlocks) * 100.0d); + if(key.equals("0") || key.equals("minecraft:air") || key.equals("minecraft:cave_air") + || key.equals("minecraft:void_air")) { + data += ",N/A"; + } else { + data += "," + Main.DECIMAL_FORMAT.format(((double) blockCounter.get(key) / totalExcludingAir) * 100.0d); + } + data += "\n"; + } + try { + File out = new File(Main.getOutputPrefix() + ".csv"); + Main.writeStringToFile(out, data); + System.out.println("\nData written to " + out.getAbsolutePath()); + } catch(IOException e) { + e.printStackTrace(); + System.exit(1); + } + if(Main.generateTable) { + try { + File out = new File(Main.getOutputPrefix() + "_table.html"); + Main.writeStringToFile(out, generateTable((double) totalBlocks, totalExcludingAir)); + System.out.println("\nTable written to " + out.getAbsolutePath()); + } catch(IOException e) { + e.printStackTrace(); + System.exit(1); + } + } + } + + public abstract void analyze(File input); public String generateTable(double totalBlocks, double totalExcludingAir) { int minY = getMinimumY(); @@ -92,7 +176,11 @@ int getMinimumY() { } } } - return min; + if(version == Version.ANVIL_2021 || version == Version.ANVIL_118) { + return min < 0 ? min : 0; + } else { + return 0; + } } int getMaximumY() { @@ -104,7 +192,11 @@ int getMaximumY() { } } } - return max; + if(version == Version.INDEV || version == Version.ALPHA || version == Version.MCREGION) { + return 128; + } else { + return max > 255 ? max : 255; + } } public enum Version { diff --git a/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerAlpha.java b/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerAlpha.java index fe2ab9c..6e03ba0 100644 --- a/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerAlpha.java +++ b/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerAlpha.java @@ -2,14 +2,9 @@ import java.io.File; import java.io.FileInputStream; -import java.io.IOException; import java.util.ArrayList; -import java.util.Comparator; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; @@ -45,82 +40,9 @@ public void analyze(File world) { "Done (" + String.format("%.2f", (double) (System.currentTimeMillis() - startTime) / 1000) + "s)"); cnum++; } - long duration = System.currentTimeMillis() - getStartTime(); - System.out.println(("Completed analysis in " + Main.millisToHMS(duration) + " (" + chunkCount + " chunks)")); - long totalBlocks = 0L; - for(String key : blockCounter.keySet()) { - totalBlocks += blockCounter.get(key); - } - System.out.println("--------------------------------\n" + blockCounter.size() + " unique blocks\n" + totalBlocks - + " blocks total\n--------------------------------"); - - System.out.print("Sorting data... "); - heightCounter = heightCounter.entrySet().stream().sorted(Map.Entry.comparingByKey(new Comparator() { - @Override - public int compare(String arg0, String arg1) { - return Long.compare(blockCounter.get(arg1), blockCounter.get(arg0)); - } - })).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); - System.out.println("Done"); - - double totalExcludingAir = (double) (totalBlocks - (blockCounter.containsKey("0") ? blockCounter.get("0") : 0)); - System.out.print("Generating CSV... "); - String data = "id,"; - for(int i = 0; i < 256; i++) { - data += i + ","; - } - data += "total,percent_of_total,percent_excluding_air\n"; - int digits = String.valueOf(blockCounter.size()).length(); - String completionFormat = "[%0" + digits + "d/%0" + digits + "d]"; - int keyIndex = 0; - for(String key : heightCounter.keySet()) { - keyIndex += 1; - System.out.print("\rGenerating CSV... " + String.format(completionFormat, keyIndex, blockCounter.size())); - data += (Main.modernizeIDs ? Main.getStringID(key) : key) + ","; - for(int i = 0; i < 256; i++) { - if(!heightCounter.get(key).containsKey(i)) { - data += "0,"; - } else { - data += heightCounter.get(key).get(i) + ","; - } - } - data += blockCounter.get(key) + "," - + Main.DECIMAL_FORMAT.format(((double) blockCounter.get(key) / (double) totalBlocks) * 100.0d); - if(key.equals("0")) { - data += ",N/A"; - } else { - data += "," + Main.DECIMAL_FORMAT.format(((double) blockCounter.get(key) / totalExcludingAir) * 100.0d); - } - data += "\n"; - } - try { - File out = new File(Main.getOutputPrefix() + ".csv"); - Main.writeStringToFile(out, data); - System.out.println("\nData written to " + out.getAbsolutePath()); - } catch(IOException e) { - e.printStackTrace(); - System.exit(1); - } - if(Main.generateTable) { - try { - File out = new File(Main.getOutputPrefix() + "_table.html"); - Main.writeStringToFile(out, generateTable((double) totalBlocks, totalExcludingAir)); - System.out.println("\nTable written to " + out.getAbsolutePath()); - } catch(IOException e) { - e.printStackTrace(); - System.exit(1); - } - } - if(Main.saveStatistics) { - try { - Main.writeStringToFile(new File(Main.getOutputPrefix() + "_stats.txt"), - "chunk-count=" + chunkCount + "\nunique-blocks=" + blockCounter.size() + "\ntotal-blocks=" - + totalBlocks + "\nduration-millis=" + duration + "\nduration-readable=" - + Main.millisToHMS(duration)); - } catch(IOException e) { - e.printStackTrace(); - } - } + endTime = System.currentTimeMillis(); + System.out.println(("Completed analysis in " + Main.millisToHMS(endTime - getStartTime()) + " (" + chunkCount + + " chunks)")); } private void processChunk(File chunkFile) throws Exception { diff --git a/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerAnvil118.java b/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerAnvil118.java index 6489d3a..648e7b0 100644 --- a/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerAnvil118.java +++ b/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerAnvil118.java @@ -2,7 +2,6 @@ import java.io.DataInputStream; import java.io.File; -import java.io.IOException; import java.util.Comparator; import java.util.Date; import java.util.HashMap; @@ -68,69 +67,6 @@ public int compare(String arg0, String arg1) { } })).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); System.out.println("Done"); - - double totalExcludingAir = (double) (totalBlocks - - (blockCounter.containsKey("minecraft:air") ? blockCounter.get("minecraft:air") : 0) - - (blockCounter.containsKey("minecraft:cave_air") ? blockCounter.get("minecraft:cave_air") : 0)); - System.out.print("Generating CSV... "); - String data = "id,"; - int minY = getMinimumY(); - int maxY = getMaximumY(); - for(int i = minY; i <= maxY; i++) { - data += i + ","; - } - data += "total,percent_of_total,percent_excluding_air\n"; - int digits = String.valueOf(blockCounter.size()).length(); - String completionFormat = "[%0" + digits + "d/%0" + digits + "d]"; - int keyIndex = 0; - for(String key : heightCounter.keySet()) { - keyIndex += 1; - System.out.print("\rGenerating CSV... " + String.format(completionFormat, keyIndex, blockCounter.size())); - data += key + ","; - for(int i = minY; i <= maxY; i++) { - if(!heightCounter.get(key).containsKey(i)) { - data += "0,"; - } else { - data += heightCounter.get(key).get(i) + ","; - } - } - data += blockCounter.get(key) + "," - + Main.DECIMAL_FORMAT.format(((double) blockCounter.get(key) / (double) totalBlocks) * 100.0d); - if(key.equals("minecraft:air") || key.equals("minecraft:cave_air")) { - data += ",N/A"; - } else { - data += "," + Main.DECIMAL_FORMAT.format(((double) blockCounter.get(key) / totalExcludingAir) * 100.0d); - } - data += "\n"; - } - try { - File out = new File(Main.getOutputPrefix() + ".csv"); - Main.writeStringToFile(out, data); - System.out.println("\nData written to " + out.getAbsolutePath()); - } catch(IOException e) { - e.printStackTrace(); - System.exit(1); - } - if(Main.generateTable) { - try { - File out = new File(Main.getOutputPrefix() + "_table.html"); - Main.writeStringToFile(out, generateTable((double) totalBlocks, totalExcludingAir)); - System.out.println("\nTable written to " + out.getAbsolutePath()); - } catch(IOException e) { - e.printStackTrace(); - System.exit(1); - } - } - if(Main.saveStatistics) { - try { - Main.writeStringToFile(new File(Main.getOutputPrefix() + "_stats.txt"), - "chunk-count=" + chunkCount + "\nunique-blocks=" + blockCounter.size() + "\ntotal-blocks=" - + totalBlocks + "\nduration-millis=" + duration + "\nduration-readable=" - + Main.millisToHMS(duration)); - } catch(IOException e) { - e.printStackTrace(); - } - } } private void processRegion(RegionFile r, String name, int x, int z) throws Exception { diff --git a/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerAnvil2012.java b/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerAnvil2012.java index b2c6e56..37200e7 100644 --- a/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerAnvil2012.java +++ b/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerAnvil2012.java @@ -2,13 +2,8 @@ import java.io.DataInputStream; import java.io.File; -import java.io.IOException; -import java.util.Comparator; import java.util.Date; import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.stream.Collectors; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; @@ -58,74 +53,6 @@ public void analyze(File regionDir) { } System.out.println("--------------------------------\n" + blockCounter.size() + " unique blocks\n" + totalBlocks + " blocks total\n--------------------------------"); - - System.out.print("Sorting data... "); - heightCounter = heightCounter.entrySet().stream().sorted(Map.Entry.comparingByKey(new Comparator() { - @Override - public int compare(String arg0, String arg1) { - return Long.compare(blockCounter.get(arg1), blockCounter.get(arg0)); - } - })).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); - System.out.println("Done"); - - double totalExcludingAir = (double) (totalBlocks - (blockCounter.containsKey("0") ? blockCounter.get("0") : 0)); - System.out.print("Generating CSV... "); - String data = "id,"; - for(int i = 0; i < 256; i++) { - data += i + ","; - } - data += "total,percent_of_total,percent_excluding_air\n"; - int digits = String.valueOf(blockCounter.size()).length(); - String completionFormat = "[%0" + digits + "d/%0" + digits + "d]"; - int keyIndex = 0; - for(String key : heightCounter.keySet()) { - keyIndex += 1; - System.out.print("\rGenerating CSV... " + String.format(completionFormat, keyIndex, blockCounter.size())); - data += (Main.modernizeIDs ? Main.getStringID(key) : key) + ","; - for(int i = 0; i < 256; i++) { - if(!heightCounter.get(key).containsKey(i)) { - data += "0,"; - } else { - data += heightCounter.get(key).get(i) + ","; - } - } - data += blockCounter.get(key) + "," - + Main.DECIMAL_FORMAT.format(((double) blockCounter.get(key) / (double) totalBlocks) * 100.0d); - if(key.equals("0")) { - data += ",N/A"; - } else { - data += "," + Main.DECIMAL_FORMAT.format(((double) blockCounter.get(key) / totalExcludingAir) * 100.0d); - } - data += "\n"; - } - try { - File out = new File(Main.getOutputPrefix() + ".csv"); - Main.writeStringToFile(out, data); - System.out.println("\nData written to " + out.getAbsolutePath()); - } catch(IOException e) { - e.printStackTrace(); - System.exit(1); - } - if(Main.generateTable) { - try { - File out = new File(Main.getOutputPrefix() + "_table.html"); - Main.writeStringToFile(out, generateTable((double) totalBlocks, totalExcludingAir)); - System.out.println("\nTable written to " + out.getAbsolutePath()); - } catch(IOException e) { - e.printStackTrace(); - System.exit(1); - } - } - if(Main.saveStatistics) { - try { - Main.writeStringToFile(new File(Main.getOutputPrefix() + "_stats.txt"), - "chunk-count=" + chunkCount + "\nunique-blocks=" + blockCounter.size() + "\ntotal-blocks=" - + totalBlocks + "\nduration-millis=" + duration + "\nduration-readable=" - + Main.millisToHMS(duration)); - } catch(IOException e) { - e.printStackTrace(); - } - } } private void processRegion(RegionFile r, String name, int x, int z) throws Exception { diff --git a/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerAnvil2018.java b/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerAnvil2018.java index 66845a8..ccf7fb5 100644 --- a/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerAnvil2018.java +++ b/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerAnvil2018.java @@ -2,13 +2,8 @@ import java.io.DataInputStream; import java.io.File; -import java.io.IOException; -import java.util.Comparator; import java.util.Date; import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.stream.Collectors; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; @@ -61,76 +56,6 @@ public void analyze(File regionDir) { } System.out.println("--------------------------------\n" + blockCounter.size() + " unique blocks\n" + totalBlocks + " blocks total\n--------------------------------"); - - System.out.print("Sorting data... "); - heightCounter = heightCounter.entrySet().stream().sorted(Map.Entry.comparingByKey(new Comparator() { - @Override - public int compare(String arg0, String arg1) { - return Long.compare(blockCounter.get(arg1), blockCounter.get(arg0)); - } - })).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); - System.out.println("Done"); - - double totalExcludingAir = (double) (totalBlocks - - (blockCounter.containsKey("minecraft:air") ? blockCounter.get("minecraft:air") : 0) - - (blockCounter.containsKey("minecraft:cave_air") ? blockCounter.get("minecraft:cave_air") : 0)); - System.out.print("Generating CSV... "); - String data = "id,"; - for(int i = 0; i < 256; i++) { - data += i + ","; - } - data += "total,percent_of_total,percent_excluding_air\n"; - int digits = String.valueOf(blockCounter.size()).length(); - String completionFormat = "[%0" + digits + "d/%0" + digits + "d]"; - int keyIndex = 0; - for(String key : heightCounter.keySet()) { - keyIndex += 1; - System.out.print("\rGenerating CSV... " + String.format(completionFormat, keyIndex, blockCounter.size())); - data += key + ","; - for(int i = 0; i < 256; i++) { - if(!heightCounter.get(key).containsKey(i)) { - data += "0,"; - } else { - data += heightCounter.get(key).get(i) + ","; - } - } - data += blockCounter.get(key) + "," - + Main.DECIMAL_FORMAT.format(((double) blockCounter.get(key) / (double) totalBlocks) * 100.0d); - if(key.equals("minecraft:air") || key.equals("minecraft:cave_air")) { - data += ",N/A"; - } else { - data += "," + Main.DECIMAL_FORMAT.format(((double) blockCounter.get(key) / totalExcludingAir) * 100.0d); - } - data += "\n"; - } - try { - File out = new File(Main.getOutputPrefix() + ".csv"); - Main.writeStringToFile(out, data); - System.out.println("\nData written to " + out.getAbsolutePath()); - } catch(IOException e) { - e.printStackTrace(); - System.exit(1); - } - if(Main.generateTable) { - try { - File out = new File(Main.getOutputPrefix() + "_table.html"); - Main.writeStringToFile(out, generateTable((double) totalBlocks, totalExcludingAir)); - System.out.println("\nTable written to " + out.getAbsolutePath()); - } catch(IOException e) { - e.printStackTrace(); - System.exit(1); - } - } - if(Main.saveStatistics) { - try { - Main.writeStringToFile(new File(Main.getOutputPrefix() + "_stats.txt"), - "chunk-count=" + chunkCount + "\nunique-blocks=" + blockCounter.size() + "\ntotal-blocks=" - + totalBlocks + "\nduration-millis=" + duration + "\nduration-readable=" - + Main.millisToHMS(duration)); - } catch(IOException e) { - e.printStackTrace(); - } - } } private void processRegion(RegionFile r, String name, int x, int z) throws Exception { diff --git a/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerAnvil2021.java b/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerAnvil2021.java index f9046b0..b22e66e 100644 --- a/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerAnvil2021.java +++ b/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerAnvil2021.java @@ -2,13 +2,8 @@ import java.io.DataInputStream; import java.io.File; -import java.io.IOException; -import java.util.Comparator; import java.util.Date; import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.stream.Collectors; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; @@ -59,78 +54,6 @@ public void analyze(File regionDir) { } System.out.println("--------------------------------\n" + blockCounter.size() + " unique blocks\n" + totalBlocks + " blocks total\n--------------------------------"); - - System.out.print("Sorting data... "); - heightCounter = heightCounter.entrySet().stream().sorted(Map.Entry.comparingByKey(new Comparator() { - @Override - public int compare(String arg0, String arg1) { - return Long.compare(blockCounter.get(arg1), blockCounter.get(arg0)); - } - })).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); - System.out.println("Done"); - - double totalExcludingAir = (double) (totalBlocks - - (blockCounter.containsKey("minecraft:air") ? blockCounter.get("minecraft:air") : 0) - - (blockCounter.containsKey("minecraft:cave_air") ? blockCounter.get("minecraft:cave_air") : 0)); - System.out.print("Generating CSV... "); - String data = "id,"; - int minY = getMinimumY(); - int maxY = getMaximumY(); - for(int i = minY; i <= maxY; i++) { - data += i + ","; - } - data += "total,percent_of_total,percent_excluding_air\n"; - int digits = String.valueOf(blockCounter.size()).length(); - String completionFormat = "[%0" + digits + "d/%0" + digits + "d]"; - int keyIndex = 0; - for(String key : heightCounter.keySet()) { - keyIndex += 1; - System.out.print("\rGenerating CSV... " + String.format(completionFormat, keyIndex, blockCounter.size())); - data += key + ","; - for(int i = minY; i <= maxY; i++) { - if(!heightCounter.get(key).containsKey(i)) { - data += "0,"; - } else { - data += heightCounter.get(key).get(i) + ","; - } - } - data += blockCounter.get(key) + "," - + Main.DECIMAL_FORMAT.format(((double) blockCounter.get(key) / (double) totalBlocks) * 100.0d); - if(key.equals("minecraft:air") || key.equals("minecraft:cave_air")) { - data += ",N/A"; - } else { - data += "," + Main.DECIMAL_FORMAT.format(((double) blockCounter.get(key) / totalExcludingAir) * 100.0d); - } - data += "\n"; - } - try { - File out = new File(Main.getOutputPrefix() + ".csv"); - Main.writeStringToFile(out, data); - System.out.println("\nData written to " + out.getAbsolutePath()); - } catch(IOException e) { - e.printStackTrace(); - System.exit(1); - } - if(Main.generateTable) { - try { - File out = new File(Main.getOutputPrefix() + "_table.html"); - Main.writeStringToFile(out, generateTable((double) totalBlocks, totalExcludingAir)); - System.out.println("\nTable written to " + out.getAbsolutePath()); - } catch(IOException e) { - e.printStackTrace(); - System.exit(1); - } - } - if(Main.saveStatistics) { - try { - Main.writeStringToFile(new File(Main.getOutputPrefix() + "_stats.txt"), - "chunk-count=" + chunkCount + "\nunique-blocks=" + blockCounter.size() + "\ntotal-blocks=" - + totalBlocks + "\nduration-millis=" + duration + "\nduration-readable=" - + Main.millisToHMS(duration)); - } catch(IOException e) { - e.printStackTrace(); - } - } } private void processRegion(RegionFile r, String name, int x, int z) throws Exception { diff --git a/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerIndev.java b/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerIndev.java index de86c3f..17b3b4f 100644 --- a/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerIndev.java +++ b/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerIndev.java @@ -2,12 +2,7 @@ import java.io.File; import java.io.FileInputStream; -import java.io.IOException; -import java.util.Comparator; import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.stream.Collectors; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; @@ -29,74 +24,6 @@ public void analyze(File world) { } System.out.println("--------------------------------\n" + blockCounter.size() + " unique blocks\n" + totalBlocks + " blocks total\n--------------------------------"); - - System.out.print("Sorting data... "); - heightCounter = heightCounter.entrySet().stream().sorted(Map.Entry.comparingByKey(new Comparator() { - @Override - public int compare(String arg0, String arg1) { - return Long.compare(blockCounter.get(arg1), blockCounter.get(arg0)); - } - })).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); - System.out.println("Done"); - - double totalExcludingAir = (double) (totalBlocks - (blockCounter.containsKey("0") ? blockCounter.get("0") : 0)); - System.out.print("Generating CSV... "); - String data = "id,"; - for(int i = 0; i < 128; i++) { - data += i + ","; - } - data += "total,percent_of_total,percent_excluding_air\n"; - int digits = String.valueOf(blockCounter.size()).length(); - String completionFormat = "[%0" + digits + "d/%0" + digits + "d]"; - int keyIndex = 0; - for(String key : heightCounter.keySet()) { - keyIndex += 1; - System.out.print("\rGenerating CSV... " + String.format(completionFormat, keyIndex, blockCounter.size())); - data += (Main.modernizeIDs ? Main.getStringID(key) : key) + ","; - for(int i = 0; i < 128; i++) { - if(!heightCounter.get(key).containsKey(i)) { - data += "0,"; - } else { - data += heightCounter.get(key).get(i) + ","; - } - } - data += blockCounter.get(key) + "," - + Main.DECIMAL_FORMAT.format(((double) blockCounter.get(key) / (double) totalBlocks) * 100.0d); - if(key.equals("0")) { - data += ",N/A"; - } else { - data += "," + Main.DECIMAL_FORMAT.format(((double) blockCounter.get(key) / totalExcludingAir) * 100.0d); - } - data += "\n"; - } - try { - File out = new File(Main.getOutputPrefix() + ".csv"); - Main.writeStringToFile(out, data); - System.out.println("\nData written to " + out.getAbsolutePath()); - } catch(IOException e) { - e.printStackTrace(); - System.exit(1); - } - if(Main.generateTable) { - try { - File out = new File(Main.getOutputPrefix() + "_table.html"); - Main.writeStringToFile(out, generateTable((double) totalBlocks, totalExcludingAir)); - System.out.println("\nTable written to " + out.getAbsolutePath()); - } catch(IOException e) { - e.printStackTrace(); - System.exit(1); - } - } - if(Main.saveStatistics) { - try { - Main.writeStringToFile(new File(Main.getOutputPrefix() + "_stats.txt"), - "chunk-count=" + chunkCount + "\nunique-blocks=" + blockCounter.size() + "\ntotal-blocks=" - + totalBlocks + "\nduration-millis=" + duration + "\nduration-readable=" - + Main.millisToHMS(duration)); - } catch(IOException e) { - e.printStackTrace(); - } - } } private void processWorld(File worldFile) throws Exception { diff --git a/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerMCRegion.java b/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerMCRegion.java index 99f5598..2f7e8f2 100644 --- a/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerMCRegion.java +++ b/src/main/java/io/github/meeples10/mcresourceanalyzer/RegionAnalyzerMCRegion.java @@ -2,13 +2,8 @@ import java.io.DataInputStream; import java.io.File; -import java.io.IOException; -import java.util.Comparator; import java.util.Date; import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.stream.Collectors; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; @@ -53,74 +48,6 @@ public void analyze(File regionDir) { } System.out.println("--------------------------------\n" + blockCounter.size() + " unique blocks\n" + totalBlocks + " blocks total\n--------------------------------"); - - System.out.print("Sorting data... "); - heightCounter = heightCounter.entrySet().stream().sorted(Map.Entry.comparingByKey(new Comparator() { - @Override - public int compare(String arg0, String arg1) { - return Long.compare(blockCounter.get(arg1), blockCounter.get(arg0)); - } - })).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); - System.out.println("Done"); - - double totalExcludingAir = (double) (totalBlocks - (blockCounter.containsKey("0") ? blockCounter.get("0") : 0)); - System.out.print("Generating CSV... "); - String data = "id,"; - for(int i = 0; i < 256; i++) { - data += i + ","; - } - data += "total,percent_of_total,percent_excluding_air\n"; - int digits = String.valueOf(blockCounter.size()).length(); - String completionFormat = "[%0" + digits + "d/%0" + digits + "d]"; - int keyIndex = 0; - for(String key : heightCounter.keySet()) { - keyIndex += 1; - System.out.print("\rGenerating CSV... " + String.format(completionFormat, keyIndex, blockCounter.size())); - data += (Main.modernizeIDs ? Main.getStringID(key) : key) + ","; - for(int i = 0; i < 256; i++) { - if(!heightCounter.get(key).containsKey(i)) { - data += "0,"; - } else { - data += heightCounter.get(key).get(i) + ","; - } - } - data += blockCounter.get(key) + "," - + Main.DECIMAL_FORMAT.format(((double) blockCounter.get(key) / (double) totalBlocks) * 100.0d); - if(key.equals("0")) { - data += ",N/A"; - } else { - data += "," + Main.DECIMAL_FORMAT.format(((double) blockCounter.get(key) / totalExcludingAir) * 100.0d); - } - data += "\n"; - } - try { - File out = new File(Main.getOutputPrefix() + ".csv"); - Main.writeStringToFile(out, data); - System.out.println("\nData written to " + out.getAbsolutePath()); - } catch(IOException e) { - e.printStackTrace(); - System.exit(1); - } - if(Main.generateTable) { - try { - File out = new File(Main.getOutputPrefix() + "_table.html"); - Main.writeStringToFile(out, generateTable((double) totalBlocks, totalExcludingAir)); - System.out.println("\nTable written to " + out.getAbsolutePath()); - } catch(IOException e) { - e.printStackTrace(); - System.exit(1); - } - } - if(Main.saveStatistics) { - try { - Main.writeStringToFile(new File(Main.getOutputPrefix() + "_stats.txt"), - "chunk-count=" + chunkCount + "\nunique-blocks=" + blockCounter.size() + "\ntotal-blocks=" - + totalBlocks + "\nduration-millis=" + duration + "\nduration-readable=" - + Main.millisToHMS(duration)); - } catch(IOException e) { - e.printStackTrace(); - } - } } private void processRegion(RegionFile r, String name, int x, int z) throws Exception {