Skip to content

Commit d92aa53

Browse files
committed
Fix level-data spawn format and remove concept of spawn-location from a World (=> Dimension)
1 parent 786917e commit d92aa53

File tree

10 files changed

+126
-32
lines changed

10 files changed

+126
-32
lines changed

common/src/main/java/de/bluecolored/bluemap/common/commands/commands/DebugCommand.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import com.flowpowered.math.vector.Vector2i;
2828
import com.flowpowered.math.vector.Vector3d;
29-
import com.flowpowered.math.vector.Vector3i;
3029
import de.bluecolored.bluecommands.annotations.Argument;
3130
import de.bluecolored.bluecommands.annotations.Command;
3231
import de.bluecolored.bluemap.common.BlueMapService;
@@ -103,7 +102,6 @@ public Component block(CommandSource source, World world, @Argument("x") int x,
103102

104103
Chunk chunk = world.getChunkAtBlock(x, z);
105104
LightData lightData = chunk.getLightData(x, y, z, new LightData(0, 0));
106-
Vector3i spawnPoint = world.getSpawnPoint();
107105

108106
return paragraph("World-Info (debug)", lines(
109107
item("position", format("( x: % | y: % | z: % )",
@@ -138,12 +136,7 @@ public Component block(CommandSource source, World world, @Argument("x") int x,
138136
.append(details(BASE_COLOR,
139137
item("name", world.getName()),
140138
item("min-y", world.getDimensionType().getMinY()),
141-
item("height", world.getDimensionType().getHeight()),
142-
item("spawn", format("( x: % | y: % | z: % )",
143-
text(spawnPoint.getX()).color(HIGHLIGHT_COLOR),
144-
text(spawnPoint.getY()).color(HIGHLIGHT_COLOR),
145-
text(spawnPoint.getZ()).color(HIGHLIGHT_COLOR)
146-
))
139+
item("height", world.getDimensionType().getHeight())
147140
))
148141
)
149142
));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class MapConfig implements MapSettings {
6060

6161
private int sorting = 0;
6262

63-
@Nullable private Vector2i startPos = null;
63+
private Vector2i startPos = Vector2i.ZERO;
6464

6565
private String skyColor = "#7dabff";
6666
private String voidColor = "#000000";

common/src/main/java/de/bluecolored/bluemap/common/rendermanager/MapUpdatePreparationTask.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,8 @@ private Collection<RenderTask> createTasks(Collection<Vector2i> regions) {
112112
ArrayList<WorldRegionRenderTask> regionTasks = new ArrayList<>(regions.size());
113113
regions.forEach(region -> regionTasks.add(new WorldRegionRenderTask(map, region, force)));
114114

115-
// get spawn region
116-
World world = map.getWorld();
117-
Vector2i spawnPoint = world.getSpawnPoint().toVector2(true);
118-
Grid regionGrid = world.getRegionGrid();
119-
Vector2i spawnRegion = regionGrid.getCell(spawnPoint);
120-
121-
// sort tasks by distance to the spawn region
122-
regionTasks.sort(WorldRegionRenderTask.defaultComparator(spawnRegion));
115+
// sort tasks by distance to 0/0
116+
regionTasks.sort(WorldRegionRenderTask.defaultComparator(Vector2i.ZERO));
123117

124118
// save map before and after the whole update
125119
ArrayList<RenderTask> tasks = new ArrayList<>(regionTasks.size() + 2);

core/src/main/java/de/bluecolored/bluemap/core/map/MapSettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public interface MapSettings extends RenderSettings {
3232

3333
int getSorting();
3434

35-
@Nullable Vector2i getStartPos();
35+
Vector2i getStartPos();
3636

3737
String getSkyColor();
3838

core/src/main/java/de/bluecolored/bluemap/core/map/MapSettingsSerializer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import de.bluecolored.bluemap.core.util.math.Color;
3434

3535
import java.lang.reflect.Type;
36-
import java.util.Optional;
3736

3837
public class MapSettingsSerializer implements JsonSerializer<BmMap> {
3938

@@ -67,9 +66,7 @@ public JsonElement serialize(BmMap map, Type typeOfSrc, JsonSerializationContext
6766
root.add("lowres", lowres);
6867

6968
// startPos
70-
Vector2i startPos = Optional.ofNullable(map.getMapSettings().getStartPos())
71-
.orElse(map.getWorld().getSpawnPoint().toVector2(true));
72-
root.add("startPos", context.serialize(startPos));
69+
root.add("startPos", context.serialize(map.getMapSettings().getStartPos()));
7370

7471
// skyColor
7572
Color skyColor = new Color().parse(map.getMapSettings().getSkyColor());

core/src/main/java/de/bluecolored/bluemap/core/world/World.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ public interface World {
4949

5050
String getName();
5151

52-
Vector3i getSpawnPoint();
53-
5452
DimensionType getDimensionType();
5553

5654
Grid getChunkGrid();

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.flowpowered.math.vector.Vector2f;
2828
import com.flowpowered.math.vector.Vector2i;
2929
import com.flowpowered.math.vector.Vector3d;
30+
import com.flowpowered.math.vector.Vector3i;
3031
import de.bluecolored.bluemap.core.util.Key;
3132
import de.bluecolored.bluemap.core.world.BlockEntity;
3233
import de.bluecolored.bluemap.core.world.BlockState;
@@ -53,6 +54,7 @@ public static BlueNBT addCommonNbtSettings(BlueNBT nbt) {
5354
nbt.register(TypeToken.of(Key.class), new KeyDeserializer());
5455
nbt.register(TypeToken.of(UUID.class), new UUIDDeserializer());
5556
nbt.register(TypeToken.of(Vector3d.class), new Vector3dDeserializer());
57+
nbt.register(TypeToken.of(Vector3i.class), new Vector3iDeserializer());
5658
nbt.register(TypeToken.of(Vector2i.class), new Vector2iDeserializer());
5759
nbt.register(TypeToken.of(Vector2f.class), new Vector2fDeserializer());
5860

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public class MCAWorld implements World {
6363
private final LevelData levelData;
6464

6565
private final DimensionType dimensionType;
66-
private final Vector3i spawnPoint;
6766
private final Path dimensionFolder;
6867

6968
private final ChunkGrid<Chunk> blockChunkGrid;
@@ -89,11 +88,6 @@ private MCAWorld(Path worldFolder, Key dimension, DataPack dataPack, LevelData l
8988
}
9089

9190
this.dimensionType = dimensionData.getType();
92-
this.spawnPoint = new Vector3i(
93-
levelData.getData().getSpawnX(),
94-
levelData.getData().getSpawnY(),
95-
levelData.getData().getSpawnZ()
96-
);
9791
this.dimensionFolder = resolveDimensionFolder(worldFolder, dimension);
9892

9993
this.blockChunkGrid = new ChunkGrid<>(new MCAChunkLoader(this), dimensionFolder.resolve("region"));

core/src/main/java/de/bluecolored/bluemap/core/world/mca/data/LevelData.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@
2424
*/
2525
package de.bluecolored.bluemap.core.world.mca.data;
2626

27+
import com.flowpowered.math.vector.Vector3i;
28+
import de.bluecolored.bluemap.core.resources.pack.datapack.DataPack;
29+
import de.bluecolored.bluemap.core.util.Key;
2730
import de.bluecolored.bluemap.core.world.DimensionType;
2831
import de.bluecolored.bluenbt.NBTName;
32+
import lombok.AccessLevel;
2933
import lombok.AllArgsConstructor;
3034
import lombok.Getter;
3135
import lombok.NoArgsConstructor;
@@ -46,17 +50,30 @@ public static class Data {
4650
@NBTName("LevelName")
4751
private String levelName = "world";
4852

53+
private Spawn spawn = null;
54+
55+
@NBTName("WorldGenSettings")
56+
private WGSettings worldGenSettings = new WGSettings();
57+
58+
// legacy-spawn notation
4959
@NBTName("SpawnX")
60+
@Getter(AccessLevel.NONE)
5061
private int spawnX = 0;
5162

5263
@NBTName("SpawnY")
64+
@Getter(AccessLevel.NONE)
5365
private int spawnY = 0;
5466

5567
@NBTName("SpawnZ")
68+
@Getter(AccessLevel.NONE)
5669
private int spawnZ = 0;
5770

58-
@NBTName("WorldGenSettings")
59-
private WGSettings worldGenSettings = new WGSettings();
71+
public Spawn getSpawn() {
72+
if (spawn == null) {
73+
spawn = new Spawn(new Vector3i(spawnX, spawnY, spawnZ));
74+
}
75+
return spawn;
76+
}
6077

6178
}
6279

@@ -72,4 +89,20 @@ public static class Dimension {
7289
private DimensionType type = DimensionType.OVERWORLD;
7390
}
7491

92+
@Getter
93+
@NoArgsConstructor
94+
@AllArgsConstructor
95+
public static class Spawn {
96+
97+
private Key dimension = DataPack.DIMENSION_OVERWORLD;
98+
private Vector3i position = Vector3i.ZERO;
99+
private float yaw = 0;
100+
private float pitch = 0;
101+
102+
public Spawn(Vector3i position) {
103+
this.position = position;
104+
}
105+
106+
}
107+
75108
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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.core.world.mca.data;
26+
27+
import com.flowpowered.math.vector.Vector3i;
28+
import de.bluecolored.bluenbt.NBTReader;
29+
import de.bluecolored.bluenbt.TagType;
30+
import de.bluecolored.bluenbt.TypeDeserializer;
31+
32+
import java.io.IOException;
33+
34+
public class Vector3iDeserializer implements TypeDeserializer<Vector3i> {
35+
36+
@Override
37+
public Vector3i read(NBTReader reader) throws IOException {
38+
TagType tag = reader.peek();
39+
40+
return switch (tag) {
41+
42+
case INT_ARRAY, LONG_ARRAY, BYTE_ARRAY -> {
43+
long[] values = reader.nextArrayAsLongArray();
44+
if (values.length != 3) throw new IllegalStateException("Unexpected array length: " + values.length);
45+
yield new Vector3i(
46+
values[0],
47+
values[1],
48+
values[2]
49+
);
50+
}
51+
52+
case LIST -> {
53+
reader.beginList();
54+
Vector3i value = new Vector3i(
55+
reader.nextInt(),
56+
reader.nextInt(),
57+
reader.nextInt()
58+
);
59+
reader.endList();
60+
yield value;
61+
}
62+
63+
case COMPOUND -> {
64+
int x = 0, y = 0, z = 0;
65+
reader.beginCompound();
66+
while (reader.peek() != TagType.END) {
67+
switch (reader.name()) {
68+
case "x" -> x = reader.nextInt();
69+
case "y" -> y = reader.nextInt();
70+
case "z" -> z = reader.nextInt();
71+
default -> reader.skip();
72+
}
73+
}
74+
reader.endCompound();
75+
yield new Vector3i(x, y, z);
76+
}
77+
78+
case null, default -> throw new IllegalStateException("Unexpected tag-type: " + tag);
79+
80+
};
81+
}
82+
83+
}

0 commit comments

Comments
 (0)