Skip to content

Commit

Permalink
Implement --version option
Browse files Browse the repository at this point in the history
  • Loading branch information
Meeples10 committed Jun 13, 2023
1 parent 8da3852 commit bb3eaab
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ java -jar mc-resource-analyzer-x.x.x.jar [-hHmsStV] [-B=PATH] [-M=PATH] [-o=STRI
- `-s`, `--statistics`: Outputs a file with statistics about the analysis.
- `-o`, `--output-prefix`: Use this argument to add a prefix to the program's output files. For example, using `-o abc` would result in the files `abc.csv` and `abc_table.html`.
- `-v`, `--version-select`: Use this argument if you want to analyze a world that was not generated with the latest version of Minecraft. Selecting a version that does not match the version with which the regions were generated may result in unexpected behavior. The following versions are supported:
- `ANVIL_118` for 1.18
- `ANVIL_118` for 1.18 to 1.20
- `ANVIL_2021` for 1.16 to 1.17
- `ANVIL_2018` for 1.13 to 1.15
- `ANVIL_2012` for 1.2 to 1.12
Expand All @@ -46,7 +46,7 @@ java -jar mc-resource-analyzer-x.x.x.jar [-hHmsStV] [-B=PATH] [-M=PATH] [-o=STRI

### Version compatibility

MCResourceAnalyzer 1.1.7 can analyze worlds generated with any version of Minecraft: Java Edition between Indev 0.31 20100122 and 1.18.
MCResourceAnalyzer 1.2.0 can analyze worlds generated with any version of Minecraft: Java Edition between Indev 0.31 20100122 and 1.20.

Note that Indev worlds with the `Long` and `Deep` world shapes are not supported.

Expand Down
20 changes: 19 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@

<groupId>io.github.meeples10.mcresourceanalyzer</groupId>
<artifactId>mc-resource-analyzer</artifactId>
<version>1.2.0-SNAPSHOT</version>
<version>1.2.0</version>
<packaging>jar</packaging>

<name>MCResourceAnalyzer</name>
<url>https://github.com/Meeples10/MCResourceAnalyzer</url>
<description>Analyze Minecraft region files to determine the empirical distribution of block types.</description>
<licenses>
<license>
<name>BSD-3-Clause</name>
<url>https://spdx.org/licenses/BSD-3-Clause.html</url>
</license>
</licenses>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyy-MM-dd</maven.build.timestamp.format>
</properties>

<dependencies>
Expand All @@ -19,6 +31,12 @@
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
21 changes: 14 additions & 7 deletions src/main/java/io/github/meeples10/mcresourceanalyzer/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,21 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import picocli.CommandLine;
import picocli.CommandLine.IVersionProvider;
import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.Model.OptionSpec;
import picocli.CommandLine.Model.PositionalParamSpec;
import picocli.CommandLine.ParseResult;

public class Main {
public static final DateFormat DATE_FORMAT = new SimpleDateFormat("dd MMM yyyy 'at' hh:mm:ss a zzz");
public static final FilenameFilter DS_STORE_FILTER = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
Expand Down Expand Up @@ -55,6 +53,7 @@ public static void main(String[] args) {
if(commandLine.getCommandName().equals("<main class>"))
commandLine.setCommandName("java -jar mc-resource-analyzer-x.x.x.jar");
if(commandLine.isUsageHelpRequested()) commandLine.usage(System.out);
if(commandLine.isVersionHelpRequested()) commandLine.printVersionHelp(System.out);
if(exitCode != 0 || commandLine.isUsageHelpRequested() || commandLine.isVersionHelpRequested())
System.exit(exitCode);
try {
Expand Down Expand Up @@ -93,7 +92,15 @@ public static void main(String[] args) {

private static CommandSpec createCommandSpec() {
CommandSpec spec = CommandSpec.create();
spec.mixinStandardHelpOptions(true);
spec.mixinStandardHelpOptions(true).versionProvider(new IVersionProvider() {
@Override
public String[] getVersion() throws Exception {
List<String> lines = readLines(Main.class.getResourceAsStream("/version.properties"));
return new String[] {
String.format("@|white,bold %s %s|@ @|faint %s|@", lines.get(0), lines.get(1), lines.get(2)),
String.format("@|yellow %s|@", lines.get(3)) };
}
});
spec.addOption(
OptionSpec.builder("-v", "--version-select").paramLabel("VERSION").type(RegionAnalyzer.Version.class)
.description("Selects the version with which the region files were generated.").build());
Expand Down Expand Up @@ -202,7 +209,6 @@ public static int[] unstream(int bitsPerValue, int wordSize, boolean slack, long
for(int i = 0; i < data.length; i++) {
for(int n = 0; n < wordSize; n++) {
int bit = (int) ((data[i] >> n) & 0x01);
// v = (v << 1) | bit;
v = (bit << bl) | v;
bl++;
if(bl >= bitsPerValue) {
Expand Down Expand Up @@ -251,14 +257,15 @@ private static void loadBlockNames() throws IOException {
for(String line : readLines(Main.class.getResourceAsStream("/blocks.properties"))) {
if(line.length() == 0) continue;
String[] split = line.split("=", 2);
BLOCK_NAMES.put(split[0], split[1]);
if(!BLOCK_NAMES.containsKey(split[0])) BLOCK_NAMES.put(split[0], split[1]);
}
}

private static void loadBlocksToMerge() throws IOException {
for(String line : readLines(Main.class.getResourceAsStream("/merge.properties"))) {
if(line.length() == 0) continue;
BLOCKS_TO_MERGE.add(Integer.valueOf(line.trim()));
int i = Integer.valueOf(line.trim());
if(!BLOCKS_TO_MERGE.contains(i)) BLOCKS_TO_MERGE.add(i);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/version.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
${project.name}
${project.version}
${timestamp}
${project.url}

0 comments on commit bb3eaab

Please sign in to comment.