Skip to content

Commit 2b644e7

Browse files
committed
Merge branch 'mc/1.13'
2 parents 2296195 + 8a43c3e commit 2b644e7

File tree

7 files changed

+50
-14
lines changed

7 files changed

+50
-14
lines changed

BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/Plugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public synchronized void load() throws IOException, ParseResourceException {
189189
World world = worlds.get(worldUUID);
190190
if (world == null) {
191191
try {
192-
world = MCAWorld.load(worldFolder.toPath(), worldUUID, configManager.getBlockIdConfig(), configManager.getBlockPropertiesConfig(), configManager.getBiomeConfig(), serverInterface.getWorldName(worldUUID));
192+
world = MCAWorld.load(worldFolder.toPath(), worldUUID, configManager.getBlockIdConfig(), configManager.getBlockPropertiesConfig(), configManager.getBiomeConfig(), serverInterface.getWorldName(worldUUID), true);
193193
worlds.put(worldUUID, world);
194194
} catch (IOException e) {
195195
Logger.global.logError("Failed to load map '" + id + "': Failed to read level.dat", e);

BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/MainConfig.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.nio.file.Paths;
3232
import java.util.ArrayList;
3333
import java.util.List;
34+
import java.util.regex.Pattern;
3435

3536
import com.flowpowered.math.vector.Vector2i;
3637
import com.flowpowered.math.vector.Vector3i;
@@ -42,6 +43,7 @@
4243
import ninja.leaping.configurate.ConfigurationNode;
4344

4445
public class MainConfig implements WebServerConfig {
46+
private static final Pattern VALID_ID_PATTERN = Pattern.compile("[a-zA-Z0-9_]+");
4547

4648
private boolean downloadAccepted = false;
4749
private boolean metricsEnabled = false;
@@ -207,6 +209,7 @@ public class MapConfig implements RenderSettings {
207209
private boolean renderEdges;
208210

209211
private boolean useGzip;
212+
private boolean ignoreMissingLightData;
210213

211214
private int hiresTileSize;
212215

@@ -216,6 +219,7 @@ public class MapConfig implements RenderSettings {
216219
private MapConfig(ConfigurationNode node) throws IOException {
217220
this.id = node.getNode("id").getString("");
218221
if (id.isEmpty()) throw new IOException("Invalid configuration: Node maps[?].id is not defined");
222+
if (!VALID_ID_PATTERN.matcher(id).matches()) throw new IOException("Invalid configuration: Node maps[?].id '" + id + "' has invalid characters in it");
219223

220224
this.name = node.getNode("name").getString(id);
221225

@@ -243,6 +247,7 @@ private MapConfig(ConfigurationNode node) throws IOException {
243247
this.renderEdges = node.getNode("renderEdges").getBoolean(true);
244248

245249
this.useGzip = node.getNode("useCompression").getBoolean(true);
250+
this.ignoreMissingLightData = node.getNode("ignoreMissingLightData").getBoolean(false);
246251

247252
this.hiresTileSize = node.getNode("hires", "tileSize").getInt(32);
248253

@@ -319,6 +324,10 @@ public boolean useGzipCompression() {
319324
return useGzip;
320325
}
321326

327+
public boolean isIgnoreMissingLightData() {
328+
return ignoreMissingLightData;
329+
}
330+
322331
}
323332

324333
private void checkOutdated(ConfigurationNode node) throws OutdatedConfigException {

BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/Chunk.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ public MCAWorld getWorld() {
7171

7272
public abstract Biome getBiome(Vector3i pos);
7373

74-
public static Chunk create(MCAWorld world, CompoundTag chunkTag) throws IOException {
74+
public static Chunk create(MCAWorld world, CompoundTag chunkTag, boolean ignoreMissingLightData) throws IOException {
7575
int version = chunkTag.getInt("DataVersion");
7676

77-
if (version <= 1343) return new ChunkAnvil112(world, chunkTag);
78-
if (version <= 1976) return new ChunkAnvil113(world, chunkTag);
79-
return new ChunkAnvil115(world, chunkTag);
77+
if (version <= 1343) return new ChunkAnvil112(world, chunkTag, ignoreMissingLightData);
78+
if (version <= 1976) return new ChunkAnvil113(world, chunkTag, ignoreMissingLightData);
79+
return new ChunkAnvil115(world, chunkTag, ignoreMissingLightData);
8080
}
8181

8282
public static Chunk empty(MCAWorld world, Vector2i chunkPos) {

BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil112.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,23 @@ public class ChunkAnvil112 extends Chunk {
4040
private BiomeMapper biomeIdMapper;
4141

4242
private boolean isGenerated;
43+
private boolean hasLight;
4344
private Section[] sections;
4445
private byte[] biomes;
4546

4647
@SuppressWarnings("unchecked")
47-
public ChunkAnvil112(MCAWorld world, CompoundTag chunkTag) {
48+
public ChunkAnvil112(MCAWorld world, CompoundTag chunkTag, boolean ignoreMissingLightData) {
4849
super(world, chunkTag);
4950

5051
blockIdMapper = getWorld().getBlockIdMapper();
5152
biomeIdMapper = getWorld().getBiomeIdMapper();
5253

5354
CompoundTag levelData = chunkTag.getCompoundTag("Level");
5455

56+
hasLight = levelData.getBoolean("LightPopulated");
57+
5558
isGenerated =
56-
levelData.getBoolean("LightPopulated") &&
59+
(hasLight || ignoreMissingLightData) &&
5760
levelData.getBoolean("TerrainPopulated");
5861

5962
sections = new Section[32]; //32 supports a max world-height of 512 which is the max that the hightmaps of Minecraft V1.13+ can store with 9 bits, i believe?
@@ -95,6 +98,8 @@ public String getBlockIdMeta(Vector3i pos) {
9598

9699
@Override
97100
public LightData getLightData(Vector3i pos) {
101+
if (!hasLight) return LightData.SKY;
102+
98103
int sectionY = MCAUtil.blockToChunk(pos.getY());
99104

100105
Section section = this.sections[sectionY];

BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil113.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ public class ChunkAnvil113 extends Chunk {
4747
private BiomeMapper biomeIdMapper;
4848

4949
private boolean isGenerated;
50+
private boolean hasLight;
5051
private Section[] sections;
5152
private int[] biomes;
5253

5354
@SuppressWarnings("unchecked")
54-
public ChunkAnvil113(MCAWorld world, CompoundTag chunkTag) {
55+
public ChunkAnvil113(MCAWorld world, CompoundTag chunkTag, boolean ignoreMissingLightData) {
5556
super(world, chunkTag);
5657

5758
biomeIdMapper = getWorld().getBiomeIdMapper();
@@ -60,6 +61,11 @@ public ChunkAnvil113(MCAWorld world, CompoundTag chunkTag) {
6061

6162
String status = levelData.getString("Status");
6263
isGenerated = status.equals("full") || status.equals("spawn"); // full is normal fully generated and spawn seems to be converted from old format but not yet loaded if you optimized your world
64+
hasLight = isGenerated;
65+
66+
if (!isGenerated && ignoreMissingLightData) {
67+
isGenerated = !status.equals("empty");
68+
}
6369

6470
sections = new Section[32]; //32 supports a max world-height of 512 which is the max that the hightmaps of Minecraft V1.13+ can store with 9 bits, i believe?
6571
if (levelData.containsKey("Sections")) {
@@ -104,6 +110,8 @@ public BlockState getBlockState(Vector3i pos) {
104110

105111
@Override
106112
public LightData getLightData(Vector3i pos) {
113+
if (!hasLight) return LightData.SKY;
114+
107115
int sectionY = MCAUtil.blockToChunk(pos.getY());
108116

109117
Section section = this.sections[sectionY];

BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil115.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ public class ChunkAnvil115 extends Chunk {
4747
private BiomeMapper biomeIdMapper;
4848

4949
private boolean isGenerated;
50+
private boolean hasLight;
5051
private Section[] sections;
5152
private int[] biomes;
5253

5354
@SuppressWarnings("unchecked")
54-
public ChunkAnvil115(MCAWorld world, CompoundTag chunkTag) {
55+
public ChunkAnvil115(MCAWorld world, CompoundTag chunkTag, boolean ignoreMissingLightData) {
5556
super(world, chunkTag);
5657

5758
biomeIdMapper = getWorld().getBiomeIdMapper();
@@ -60,6 +61,11 @@ public ChunkAnvil115(MCAWorld world, CompoundTag chunkTag) {
6061

6162
String status = levelData.getString("Status");
6263
isGenerated = status.equals("full") || status.equals("spawn"); // full is normal fully generated and spawn seems to be converted from old format but not yet loaded if you optimized your world
64+
hasLight = isGenerated;
65+
66+
if (!isGenerated && ignoreMissingLightData) {
67+
isGenerated = !status.equals("empty");
68+
}
6369

6470
sections = new Section[32]; //32 supports a max world-height of 512 which is the max that the hightmaps of Minecraft V1.13+ can store with 9 bits, i believe?
6571
if (levelData.containsKey("Sections")) {
@@ -104,6 +110,8 @@ public BlockState getBlockState(Vector3i pos) {
104110

105111
@Override
106112
public LightData getLightData(Vector3i pos) {
113+
if (!hasLight) return LightData.SKY;
114+
107115
int sectionY = MCAUtil.blockToChunk(pos.getY());
108116

109117
Section section = this.sections[sectionY];

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ public class MCAWorld implements World {
111111
private BlockPropertiesMapper blockPropertiesMapper;
112112
private BiomeMapper biomeMapper;
113113

114+
private boolean ignoreMissingLightData;
115+
114116
private Map<Integer, String> forgeBlockMappings;
115117

116118
private MCAWorld(
@@ -122,7 +124,8 @@ private MCAWorld(
122124
Vector3i spawnPoint,
123125
BlockIdMapper blockIdMapper,
124126
BlockPropertiesMapper blockPropertiesMapper,
125-
BiomeMapper biomeMapper
127+
BiomeMapper biomeMapper,
128+
boolean ignoreMissingLightData
126129
) {
127130
this.uuid = uuid;
128131
this.worldFolder = worldFolder;
@@ -134,6 +137,8 @@ private MCAWorld(
134137
this.blockPropertiesMapper = blockPropertiesMapper;
135138
this.biomeMapper = biomeMapper;
136139

140+
this.ignoreMissingLightData = ignoreMissingLightData;
141+
137142
this.forgeBlockMappings = new HashMap<>();
138143
}
139144

@@ -244,7 +249,7 @@ private Chunk loadChunk(Vector2i chunkPos) throws IOException {
244249
DataInputStream dis = new DataInputStream(new BufferedInputStream(compressionType.decompress(new FileInputStream(raf.getFD()))));
245250
Tag<?> tag = Tag.deserialize(dis, Tag.DEFAULT_MAX_DEPTH);
246251
if (tag instanceof CompoundTag) {
247-
return Chunk.create(this, (CompoundTag) tag);
252+
return Chunk.create(this, (CompoundTag) tag, ignoreMissingLightData);
248253
} else {
249254
throw new IOException("invalid data tag: " + (tag == null ? "null" : tag.getClass().getName()));
250255
}
@@ -379,10 +384,10 @@ private Path getMCAFilePath(Vector2i region) {
379384
}
380385

381386
public static MCAWorld load(Path worldFolder, UUID uuid, BlockIdMapper blockIdMapper, BlockPropertiesMapper blockPropertiesMapper, BiomeMapper biomeIdMapper) throws IOException {
382-
return load(worldFolder, uuid, blockIdMapper, blockPropertiesMapper, biomeIdMapper, null);
387+
return load(worldFolder, uuid, blockIdMapper, blockPropertiesMapper, biomeIdMapper, null, false);
383388
}
384389

385-
public static MCAWorld load(Path worldFolder, UUID uuid, BlockIdMapper blockIdMapper, BlockPropertiesMapper blockPropertiesMapper, BiomeMapper biomeIdMapper, String name) throws IOException {
390+
public static MCAWorld load(Path worldFolder, UUID uuid, BlockIdMapper blockIdMapper, BlockPropertiesMapper blockPropertiesMapper, BiomeMapper biomeIdMapper, String name, boolean ignoreMissingLightData) throws IOException {
386391
try {
387392
boolean subDimension = false;
388393

@@ -423,7 +428,8 @@ public static MCAWorld load(Path worldFolder, UUID uuid, BlockIdMapper blockIdMa
423428
spawnPoint,
424429
blockIdMapper,
425430
blockPropertiesMapper,
426-
biomeIdMapper
431+
biomeIdMapper,
432+
ignoreMissingLightData
427433
);
428434

429435
try {

0 commit comments

Comments
 (0)