-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added filtering of "Spurious Regions". - initial cut at McaDump for analyzing region files. - added timeStampAt() to RegionFile, so we can retrieve chunk timestamps. (to be used later in chunk-resolution heatmap generation)
- Loading branch information
Simon Hunt
committed
Jun 29, 2016
1 parent
e0e7839
commit b20aa7d
Showing
10 changed files
with
259 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.meowster.mcquad; | ||
|
||
import java.io.File; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import static com.meowster.util.StringUtils.printErr; | ||
import static java.lang.System.exit; | ||
|
||
/** | ||
* Command-line based region file analysis program, for dumping information | ||
* about MCA (Minecraft Anvil format) files. | ||
* <pre> | ||
* Usage: com.meowster.mcquad.McaDump {region file}. | ||
* </pre> | ||
*/ | ||
public class McaDump { | ||
|
||
private static final Pattern RE_REGION_FILE = | ||
Pattern.compile("^r\\.(-?\\d+)\\.(-?\\d+)\\.mca$"); | ||
|
||
private McaDump(File mca) { | ||
Matcher m = RE_REGION_FILE.matcher(mca.getName()); | ||
if (m.matches()) { | ||
int x = Integer.parseInt(m.group(1)); | ||
int z = Integer.parseInt(m.group(2)); | ||
Region region = new Region(x, z, mca); | ||
RegionDataDump.analyze(region); | ||
} else { | ||
printErr("No match?? {}", mca.getName()); | ||
exit(1); | ||
} | ||
} | ||
|
||
private static int usage() { | ||
System.out.println("Usage: McaDump {region file}"); | ||
return 2; | ||
} | ||
|
||
/** | ||
* Main entry point. | ||
* | ||
* @param args command line arguments. | ||
*/ | ||
public static void main(String[] args) { | ||
if (args.length != 1) { | ||
exit(usage()); | ||
} | ||
File mca = new File(args[0]); | ||
if (!mca.canRead()) { | ||
printErr("Unable to read file: {}", args[0]); | ||
exit(usage()); | ||
} | ||
new McaDump(mca); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
core/src/main/java/com/meowster/mcquad/RegionDataDump.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.meowster.mcquad; | ||
|
||
import java.io.DataInputStream; | ||
|
||
import static com.meowster.util.StringUtils.EOL; | ||
import static com.meowster.util.StringUtils.printOut; | ||
|
||
/** | ||
* Analysis of a region file. | ||
*/ | ||
class RegionDataDump { | ||
|
||
private static final String HASH = " #"; | ||
private static final String DOT = " ."; | ||
|
||
private static final int NCHUNKS = 32; // chunk dimension of region | ||
private static final int NBLOCKS = 16; // block dimension of chunk | ||
|
||
private static final int CHUNKS_PER_REGION = NCHUNKS * NCHUNKS; | ||
|
||
|
||
private static Region region; | ||
private static int totalChunks; | ||
private static ChunkStuff[][] data; | ||
private static int singleX; | ||
private static int singleZ; | ||
|
||
/** | ||
* Analyze the region and output results. | ||
* | ||
* @param r the region to analyze | ||
*/ | ||
static void analyze(Region r) { | ||
region = r; | ||
totalChunks = 0; | ||
data = new ChunkStuff[NCHUNKS][NCHUNKS]; | ||
|
||
// iterate over the chunks in the region... | ||
for (int cz = 0; cz < NCHUNKS; cz++) { | ||
for (int cx = 0; cx < NCHUNKS; cx++) { | ||
DataInputStream dis = region.getChunkDataStream(cx, cz); | ||
if (dis == null) | ||
continue; | ||
|
||
totalChunks++; | ||
singleX = cx; | ||
singleZ = cz; | ||
|
||
// Chunk chunk = new Chunk(dis); | ||
data[cz][cx] = new ChunkStuff(null); | ||
} | ||
} | ||
|
||
outputResults(); | ||
} | ||
|
||
|
||
private static void outputResults() { | ||
printOut("Region: {}; Chunks: {}/{}", | ||
region.regionFile().getName(), | ||
totalChunks, | ||
CHUNKS_PER_REGION | ||
); | ||
if (totalChunks == 1) { | ||
printOut(" Chunk coords [{}, {}]", singleX, singleZ); | ||
} | ||
// printOut(createMap()); | ||
} | ||
|
||
private static String createMap() { | ||
StringBuilder sb = new StringBuilder(); | ||
for (int cz = 0; cz < NCHUNKS; cz++) { | ||
for (int cx = 0; cx < NCHUNKS; cx++) { | ||
sb.append(data[cz][cx] != null ? HASH : DOT); | ||
} | ||
sb.append(EOL); | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
|
||
// retains info about a chunk | ||
private static class ChunkStuff { | ||
ChunkStuff(Chunk chunk) { | ||
// capture any data we need for dumping... | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
|
||
MCQUAD_VERSION=1.2.2 | ||
|
||
MAIN=com.meowster.mcquad.McaDump | ||
|
||
CP="/Users/simonh/dev/mcquad/McQuad/core/target/classes" | ||
|
||
MCSAVES="/Users/simonh/dev/mcquad/tmp" | ||
|
||
ls "$MCSAVES" | ||
|
||
JAVA=/usr/bin/java | ||
|
||
|
||
for FILE in $(ls "$MCSAVES"); | ||
do | ||
$JAVA -cp $CP $MAIN "$MCSAVES/$FILE" | ||
done | ||
|
||
|