Skip to content

Commit 9b8c10f

Browse files
committed
Add render-masks. Closes: #81
1 parent 17cadd2 commit 9b8c10f

File tree

26 files changed

+998
-91
lines changed

26 files changed

+998
-91
lines changed

common/src/main/java/de/bluecolored/bluemap/common/config/BlueMapConfigManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ private Map<String, MapConfig> loadMapConfigs(Collection<ServerWorld> autoConfig
310310
}
311311

312312
MapConfig mapConfig = configManager.loadConfig(configFile, MapConfig.class);
313+
mapConfig.checkLegacy();
313314
mapConfigs.put(id, mapConfig);
314315
}
315316
} catch (IOException ex) {

common/src/main/java/de/bluecolored/bluemap/common/config/ConfigManager.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@
2424
*/
2525
package de.bluecolored.bluemap.common.config;
2626

27+
import com.flowpowered.math.vector.Vector2d;
2728
import com.flowpowered.math.vector.Vector2i;
29+
import de.bluecolored.bluemap.common.config.mask.MaskConfig;
2830
import de.bluecolored.bluemap.common.config.storage.StorageConfig;
29-
import de.bluecolored.bluemap.common.config.typeserializer.KeyTypeSerializer;
30-
import de.bluecolored.bluemap.common.config.typeserializer.ObjectMapperSerializer;
31-
import de.bluecolored.bluemap.common.config.typeserializer.Vector2iTypeSerializer;
31+
import de.bluecolored.bluemap.common.config.typeserializer.*;
3232
import de.bluecolored.bluemap.core.BlueMap;
33+
import de.bluecolored.bluemap.core.map.mask.CombinedMask;
3334
import de.bluecolored.bluemap.core.util.Key;
3435
import de.bluecolored.bluenbt.TypeToken;
3536
import org.spongepowered.configurate.ConfigurateException;
@@ -161,10 +162,13 @@ private ConfigurationLoader<? extends ConfigurationNode> getLoader(Path path){
161162
.path(path)
162163
.defaultOptions(o -> o.serializers(b -> {
163164
b.register(Vector2i.class, new Vector2iTypeSerializer());
165+
b.register(Vector2d.class, new Vector2dTypeSerializer());
164166
b.register(Key.class, new KeyTypeSerializer());
167+
b.register(CombinedMask.class, new CombinedMaskSerializer());
165168

166-
// try parse any StorageConfig type, even without the @ConfigSerializable annotation
167-
b.register(type -> TypeToken.of(type).is(StorageConfig.class), new ObjectMapperSerializer());
169+
// ignore missing @ConfigSerializable annotation for subtypes of the following types
170+
b.register(type -> TypeToken.of(type).is( StorageConfig.class ), new ObjectMapperSerializer());
171+
b.register(type -> TypeToken.of(type).is( MaskConfig.class ), new ObjectMapperSerializer());
168172

169173
}))
170174
.build();

common/src/main/java/de/bluecolored/bluemap/common/config/ConfigurationException.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ public String getExplanation() {
6565

6666
public String getFullExplanation() {
6767
Throwable cause = getCause();
68-
if (cause instanceof ConfigurationException) {
68+
while (cause != null && !(cause instanceof ConfigurationException)) {
69+
cause = cause.getCause();
70+
}
71+
72+
if (cause != null) {
6973
return getExplanation() + "\n\n" + ((ConfigurationException) cause).getFullExplanation();
7074
} else {
7175
return getExplanation();

common/src/main/java/de/bluecolored/bluemap/common/config/MapConfig.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import de.bluecolored.bluemap.api.gson.MarkerGson;
3535
import de.bluecolored.bluemap.api.markers.MarkerSet;
3636
import de.bluecolored.bluemap.core.map.MapSettings;
37+
import de.bluecolored.bluemap.core.map.mask.CombinedMask;
3738
import de.bluecolored.bluemap.core.util.Key;
3839
import lombok.AccessLevel;
3940
import lombok.Getter;
@@ -72,15 +73,7 @@ public class MapConfig implements MapSettings {
7273
private int caveDetectionOceanFloor = 10000;
7374
private boolean caveDetectionUsesBlockLight = false;
7475

75-
@Getter(AccessLevel.NONE) private int minX = Integer.MIN_VALUE;
76-
@Getter(AccessLevel.NONE) private int maxX = Integer.MAX_VALUE;
77-
@Getter(AccessLevel.NONE) private int minZ = Integer.MIN_VALUE;
78-
@Getter(AccessLevel.NONE) private int maxZ = Integer.MAX_VALUE;
79-
@Getter(AccessLevel.NONE) private int minY = Integer.MIN_VALUE;
80-
@Getter(AccessLevel.NONE) private int maxY = Integer.MAX_VALUE;
81-
82-
private transient Vector3i min = null;
83-
private transient Vector3i max = null;
76+
private CombinedMask renderMask = new CombinedMask();
8477

8578
private long minInhabitedTime = 0;
8679
private int minInhabitedTimeRadius = 0;
@@ -106,16 +99,6 @@ public class MapConfig implements MapSettings {
10699
private int lodCount = 3;
107100
private int lodFactor = 5;
108101

109-
public Vector3i getMinPos() {
110-
if (min == null) min = new Vector3i(minX, minY, minZ);
111-
return min;
112-
}
113-
114-
public Vector3i getMaxPos() {
115-
if (max == null) max = new Vector3i(maxX, maxY, maxZ);
116-
return max;
117-
}
118-
119102
/**
120103
* parse marker-config by converting it first from hocon to json and then loading it with MarkerGson
121104
*/
@@ -138,4 +121,21 @@ public Map<String, MarkerSet> parseMarkerSets() throws ConfigurationException {
138121
}
139122
}
140123

124+
// ## legacy check ##
125+
@SuppressWarnings("unused")
126+
@Getter(AccessLevel.NONE)
127+
private Integer minX, maxX, minZ, maxZ, minY, maxY;
128+
public void checkLegacy() throws ConfigurationException {
129+
if (
130+
minX != null || maxX != null ||
131+
minZ != null || maxZ != null ||
132+
minY != null || maxY != null
133+
) throw new ConfigurationException("""
134+
Your map-configuration is outdated!
135+
Looks like you updated BlueMap but did not follow the upgrade-instructions correctly.
136+
To fix your config, make sure to follow all relevant upgrade-instructions from BlueMap's changelogs.
137+
You can find them here: https://github.com/BlueMap-Minecraft/BlueMap/releases
138+
""".trim());
139+
}
140+
141141
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package de.bluecolored.bluemap.common.config.mask;
2+
3+
import de.bluecolored.bluemap.core.map.mask.BlurMask;
4+
import de.bluecolored.bluemap.core.map.mask.CombinedMask;
5+
import de.bluecolored.bluemap.core.map.mask.Mask;
6+
import lombok.Getter;
7+
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
8+
9+
@SuppressWarnings("FieldMayBeFinal")
10+
@ConfigSerializable
11+
@Getter
12+
public class BlurMaskConfig extends MaskConfig {
13+
14+
private int size = 5;
15+
private CombinedMask masks = new CombinedMask();
16+
17+
@Override
18+
public Mask createMask() {
19+
return size > 0 ? new BlurMask(masks, size) : masks;
20+
}
21+
22+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package de.bluecolored.bluemap.common.config.mask;
2+
3+
import com.flowpowered.math.vector.Vector3i;
4+
import de.bluecolored.bluemap.common.config.ConfigurationException;
5+
import de.bluecolored.bluemap.core.map.mask.BoxMask;
6+
import de.bluecolored.bluemap.core.map.mask.Mask;
7+
import lombok.Getter;
8+
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
9+
10+
@SuppressWarnings("FieldMayBeFinal")
11+
@ConfigSerializable
12+
@Getter
13+
public class BoxMaskConfig extends MaskConfig {
14+
15+
private int
16+
minX = Integer.MIN_VALUE,
17+
minY = Integer.MIN_VALUE,
18+
minZ = Integer.MIN_VALUE,
19+
maxX = Integer.MAX_VALUE,
20+
maxY = Integer.MAX_VALUE,
21+
maxZ = Integer.MAX_VALUE;
22+
23+
@Override
24+
public Mask createMask() throws ConfigurationException {
25+
if (minX > maxX || minY > maxY || minZ > maxZ) {
26+
throw new ConfigurationException("""
27+
The box-mask configuration results in a collapsed volume.
28+
Make sure that all "min-" values are actually SMALLER than their "max-" counterparts.
29+
""".trim());
30+
}
31+
32+
return new BoxMask(
33+
new Vector3i(minX, minY, minZ),
34+
new Vector3i(maxX, maxY, maxZ)
35+
);
36+
}
37+
38+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package de.bluecolored.bluemap.common.config.mask;
2+
3+
import com.flowpowered.math.vector.Vector2d;
4+
import de.bluecolored.bluemap.common.config.ConfigurationException;
5+
import de.bluecolored.bluemap.core.map.mask.EllipseMask;
6+
import de.bluecolored.bluemap.core.map.mask.Mask;
7+
import lombok.Getter;
8+
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
9+
10+
@SuppressWarnings("FieldMayBeFinal")
11+
@ConfigSerializable
12+
@Getter
13+
public class CircleMaskConfig extends MaskConfig {
14+
15+
private double
16+
centerX = 0,
17+
centerZ = 0;
18+
private double radius = Double.MAX_VALUE;
19+
private int
20+
minY = Integer.MIN_VALUE,
21+
maxY = Integer.MAX_VALUE;
22+
23+
@Override
24+
public Mask createMask() throws ConfigurationException {
25+
if (minY > maxY) {
26+
throw new ConfigurationException("""
27+
The circle-mask configuration results in a collapsed volume.
28+
Make sure that the "min-y" value is actually SMALLER than the "max-y" counterpart.
29+
""".trim());
30+
}
31+
32+
if (radius <= 0) {
33+
throw new ConfigurationException("""
34+
The circle-mask configuration results in a collapsed volume.
35+
Make sure that the "radius" value is greater than 0.
36+
""".trim());
37+
}
38+
39+
return new EllipseMask(
40+
new Vector2d(centerX, centerZ),
41+
radius,
42+
minY, maxY
43+
);
44+
}
45+
46+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package de.bluecolored.bluemap.common.config.mask;
2+
3+
import com.flowpowered.math.vector.Vector2d;
4+
import de.bluecolored.bluemap.common.config.ConfigurationException;
5+
import de.bluecolored.bluemap.core.map.mask.EllipseMask;
6+
import de.bluecolored.bluemap.core.map.mask.Mask;
7+
import lombok.Getter;
8+
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
9+
10+
@SuppressWarnings("FieldMayBeFinal")
11+
@ConfigSerializable
12+
@Getter
13+
public class EllipseMaskConfig extends MaskConfig {
14+
15+
private double
16+
centerX = 0,
17+
centerZ = 0;
18+
private double radiusX = Double.MAX_VALUE;
19+
private double radiusZ = Double.MAX_VALUE;
20+
private int
21+
minY = Integer.MIN_VALUE,
22+
maxY = Integer.MAX_VALUE;
23+
24+
@Override
25+
public Mask createMask() throws ConfigurationException {
26+
if (minY > maxY) {
27+
throw new ConfigurationException("""
28+
The circle-mask configuration results in a collapsed volume.
29+
Make sure that the "min-y" value is actually SMALLER than the "max-y" counterpart.
30+
""".trim());
31+
}
32+
33+
if (radiusX <= 0 || radiusZ <= 0) {
34+
throw new ConfigurationException("""
35+
The ellipse-mask configuration results in a collapsed volume.
36+
Make sure that the radius values are greater than 0.
37+
""".trim());
38+
}
39+
40+
return new EllipseMask(
41+
new Vector2d(centerX, centerZ),
42+
radiusX, radiusZ,
43+
minY, maxY
44+
);
45+
}
46+
47+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* This file is part of BlueMap, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package de.bluecolored.bluemap.common.config.mask;
26+
27+
import de.bluecolored.bluemap.common.config.ConfigurationException;
28+
import de.bluecolored.bluemap.core.map.mask.CombinedMask;
29+
import de.bluecolored.bluemap.core.map.mask.Mask;
30+
import de.bluecolored.bluemap.core.util.Key;
31+
import de.bluecolored.bluemap.core.util.Keyed;
32+
import de.bluecolored.bluemap.core.util.Registry;
33+
import lombok.Getter;
34+
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
35+
36+
@SuppressWarnings("FieldMayBeFinal")
37+
@ConfigSerializable
38+
public abstract class MaskConfig {
39+
40+
private String type = MaskType.BOX.getKey().getFormatted();
41+
@Getter private boolean subtract = false;
42+
43+
public MaskType getMaskType() throws ConfigurationException {
44+
return parseKey(MaskType.REGISTRY, type, "mask-type");
45+
}
46+
47+
public abstract Mask createMask() throws ConfigurationException;
48+
49+
public void addTo(CombinedMask combinedMask) throws ConfigurationException {
50+
Mask mask = createMask();
51+
combinedMask.add(mask, !subtract);
52+
}
53+
54+
static <T extends Keyed> T parseKey(Registry<T> registry, String key, String typeName) throws ConfigurationException {
55+
T type = registry.get(Key.parse(key, Key.BLUEMAP_NAMESPACE));
56+
57+
if (type == null)
58+
throw new ConfigurationException("No " + typeName + " found for key: " + key + "!");
59+
60+
return type;
61+
}
62+
63+
@ConfigSerializable
64+
public static class Base extends MaskConfig {
65+
66+
@Override
67+
public Mask createMask() {
68+
throw new UnsupportedOperationException();
69+
}
70+
71+
}
72+
73+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package de.bluecolored.bluemap.common.config.mask;
2+
3+
import de.bluecolored.bluemap.core.util.Key;
4+
import de.bluecolored.bluemap.core.util.Keyed;
5+
import de.bluecolored.bluemap.core.util.Registry;
6+
import lombok.Getter;
7+
import lombok.RequiredArgsConstructor;
8+
9+
public interface MaskType extends Keyed {
10+
11+
MaskType BOX = new Impl(Key.bluemap("box"), BoxMaskConfig.class);
12+
MaskType CIRCLE = new Impl(Key.bluemap("circle"), CircleMaskConfig.class);
13+
MaskType ELLIPSE = new Impl(Key.bluemap("ellipse"), EllipseMaskConfig.class);
14+
MaskType POLYGON = new Impl(Key.bluemap("polygon"), PolygonMaskConfig.class);
15+
MaskType BLUR = new Impl(Key.bluemap("blur"), BlurMaskConfig.class);
16+
17+
Registry<MaskType> REGISTRY = new Registry<>(
18+
BOX,
19+
CIRCLE,
20+
ELLIPSE,
21+
POLYGON,
22+
BLUR
23+
);
24+
25+
Class<? extends MaskConfig> getConfigType();
26+
27+
@RequiredArgsConstructor
28+
@Getter
29+
class Impl implements MaskType {
30+
31+
private final Key key;
32+
private final Class<? extends MaskConfig> configType;
33+
34+
}
35+
36+
}

0 commit comments

Comments
 (0)