Skip to content

Commit 2a4e3fb

Browse files
committed
Restore abillity to load pre 26.1 formatted worlds
1 parent db9df98 commit 2a4e3fb

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

  • core/src/main/java/de/bluecolored/bluemap/core/world/mca

core/src/main/java/de/bluecolored/bluemap/core/world/mca/MCAWorld.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import de.bluecolored.bluenbt.TypeToken;
4646
import lombok.Getter;
4747
import lombok.ToString;
48+
import org.jetbrains.annotations.Nullable;
4849

4950
import java.io.IOException;
5051
import java.io.InputStream;
@@ -182,13 +183,19 @@ public static Path resolveDimensionFolder(Path worldFolder, Key dimension) {
182183

183184
public static DimensionType loadDimensionType(Path worldFolder, Key dimension, DataPack dataPack) throws IOException {
184185
BlueNBT blueNBT = createBlueNBTForDataPack(dataPack);
186+
DimensionSettings dimensionSettings = null;
187+
185188
WorldGenSettings worldGenSettings = load(WorldGenSettings.class, worldFolder.resolve("data/minecraft/world_gen_settings.dat"), blueNBT);
186-
DimensionSettings dimensionSettings = worldGenSettings.getData().getDimensions().get(dimension.getFormatted());
189+
if (worldGenSettings != null) {
190+
dimensionSettings = worldGenSettings.getData().getDimensions().get(dimension.getFormatted());
191+
}
187192

188193
if (dimensionSettings == null) {
189194
// try loading from the level.dat instead (old world format)
190195
LevelData levelData = load(LevelData.class, worldFolder.resolve("level.dat"), blueNBT);
191-
dimensionSettings = levelData.getData().getWorldGenSettings().getDimensions().get(dimension.getFormatted());
196+
if (levelData != null) {
197+
dimensionSettings = levelData.getData().getWorldGenSettings().getDimensions().get(dimension.getFormatted());
198+
}
192199
}
193200

194201
if (dimensionSettings != null) return dimensionSettings.getType();
@@ -208,7 +215,8 @@ private static BlueNBT createBlueNBTForDataPack(DataPack dataPack) {
208215
return blueNBT;
209216
}
210217

211-
private static <T> T load(Class<T> type, Path path, BlueNBT blueNBT) throws IOException {
218+
private static <T> @Nullable T load(Class<T> type, Path path, BlueNBT blueNBT) throws IOException {
219+
if (!Files.exists(path)) return null;
212220
try (InputStream fileIn = Compression.GZIP.decompress(Files.newInputStream(path))) {
213221
return blueNBT.read(fileIn, type);
214222
}

0 commit comments

Comments
 (0)