Skip to content

Commit

Permalink
Skip chunks that havent finished generating enough
Browse files Browse the repository at this point in the history
Fixes #1
  • Loading branch information
TechnicJelle committed Jan 1, 2024
1 parent 0791058 commit 2ee435e
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
package com.technicjelle.bluemapsignextractor.common;

import java.util.Set;

public interface Chunk {
Set<String> FINISHED_STATUSES = Set.of(
//1.20: //1.14 - 1.18:
"minecraft:features", "features",
"minecraft:light", "light", //the wiki says this exists, but I cannot find it anywhere
"minecraft:initialize_light", "initialize_light", //this one isn't on the wiki, but it's in my test world files
"minecraft:spawn", "spawn",
"minecraft:full", "full",
//1.13:
"carved",
"liquid_carved",
"decorated",
"postprocessed",
"fullchunk"
);

BlockEntity[] getBlockEntities();

int getDataVersion();

boolean isGenerated();
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public ArrayList<BlockEntity> getBlockEntities() throws IOException {
chunk = nbt.read(reader2, chunkClass);
}

if (!chunk.isGenerated()) continue;

BlockEntity[] chunkBlockEntities = chunk.getBlockEntities();
if (chunkBlockEntities == null) {
throw new IOException("chunkBlockEntities was null in chunk " + x + ", " + z + " in region file " + regionFile.toAbsolutePath() + "\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public class MC_1_13_2_Chunk extends ChunkWithVersion implements Chunk {
static class Level {
@NBTName("TileEntities")
public MC_1_13_2_Sign[] tileEntities;

@NBTName("Status")
private String status;
}

@NBTName("Level")
Expand All @@ -18,4 +21,9 @@ static class Level {
public BlockEntity[] getBlockEntities() {
return level.tileEntities;
}

@Override
public boolean isGenerated() {
return Chunk.FINISHED_STATUSES.contains(level.status);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public class MC_1_14_4_Chunk extends ChunkWithVersion implements Chunk {
static class Level {
@NBTName("TileEntities")
public MC_1_14_4_Sign[] tileEntities;

@NBTName("Status")
private String status;
}

@NBTName("Level")
Expand All @@ -18,4 +21,9 @@ static class Level {
public BlockEntity[] getBlockEntities() {
return level.tileEntities;
}

@Override
public boolean isGenerated() {
return Chunk.FINISHED_STATUSES.contains(level.status);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public class MC_1_17_1_Chunk extends ChunkWithVersion implements Chunk {
static class Level {
@NBTName("TileEntities")
public MC_1_17_1_Sign[] tileEntities;

@NBTName("Status")
private String status;
}

@NBTName("Level")
Expand All @@ -18,4 +21,9 @@ static class Level {
public BlockEntity[] getBlockEntities() {
return level.tileEntities;
}

@Override
public boolean isGenerated() {
return Chunk.FINISHED_STATUSES.contains(level.status);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ public class MC_1_18_2_Chunk extends ChunkWithVersion implements Chunk {
@NBTName("block_entities")
private MC_1_17_1_Sign[] blockEntities; //The actual sign format hasn't changed, only the chunk format has

@NBTName("Status")
private String status;

@Override
public BlockEntity[] getBlockEntities() {
return blockEntities;
}

@Override
public boolean isGenerated() {
return Chunk.FINISHED_STATUSES.contains(status);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ public class MC_1_20_4_Chunk extends ChunkWithVersion implements Chunk {
@NBTName("block_entities")
private MC_1_20_4_Sign[] blockEntities;

@NBTName("Status")
private String status;

@Override
public BlockEntity[] getBlockEntities() {
if (blockEntities == null) System.err.println("no block entities found here");
return blockEntities;
}

@Override
public boolean isGenerated() {
return Chunk.FINISHED_STATUSES.contains(status);
}
}
4 changes: 2 additions & 2 deletions src/test/java/LoadRegionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public void test_MC_1_20_4_Upgraded() throws IOException {
public void test_MC_1_20_4_IncompleteChunk() throws IOException {
//Chunk files with incompletely generated chunks.
// Thanks to GitHub user @bold-gman for providing these files.
testMCAFile("/MC_1_20_4/r.-2.5.mca", 1);
testMCAFile("/MC_1_20_4/r.-98.8.mca", 1);
testMCAFile("/MC_1_20_4/r.-2.5.mca", 0);
testMCAFile("/MC_1_20_4/r.-98.8.mca", 0);
}

@Test
Expand Down

0 comments on commit 2ee435e

Please sign in to comment.