Skip to content

Commit a56b610

Browse files
committed
Add configuration to set a start-point of the map, defaults to world-spawn
1 parent 3e2fa6d commit a56b610

File tree

9 files changed

+60
-38
lines changed

9 files changed

+60
-38
lines changed

BlueMapBukkit/src/main/resources/bluemap-bukkit.conf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ renderThreadCount: -2
2424

2525
# If this is true, BlueMap might send really basic metrics reports containg only the implementation-type and the version that is being used to https://metrics.bluecolored.de/bluemap/
2626
# This allows me to track the basic usage of BlueMap and helps me stay motivated to further develop this tool! Please leave it on :)
27-
# An example report looks like this: {"implementation":"CLI","version":"%version%"}
27+
# An example report looks like this: {"implementation":"bukkit","version":"%version%"}
2828
metrics: true
2929

3030
# The folder where bluemap saves data-files it needs during runtime or to save e.g. the render-progress to resume it later.
@@ -74,6 +74,10 @@ maps: [
7474

7575
# The path to the save-folder of the world to render
7676
world: "world"
77+
78+
# The position on the world where the map will be centered if you open it.
79+
# This defaults to the world-spawn if you don't set it.
80+
#startPos: [500, -820]
7781

7882
# If this is false, BlueMap tries to omit all blocks that are not visible from above-ground.
7983
# More specific: Block-Faces that have a sunlight/skylight value of 0 are removed.

BlueMapCLI/src/main/java/de/bluecolored/bluemap/cli/BlueMapCLI.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,14 @@ public void renderMaps() throws IOException {
136136
webSettings.setAllEnabled(false);
137137
for (MapType map : maps.values()) {
138138
webSettings.setEnabled(true, map.getId());
139-
webSettings.setName(map.getName(), map.getId());
140139
webSettings.setFrom(map.getTileRenderer(), map.getId());
140+
webSettings.setFrom(map.getWorld(), map.getId());
141141
}
142142
int ordinal = 0;
143143
for (MapConfig map : config.getMapConfigs()) {
144144
if (!maps.containsKey(map.getId())) continue; //don't add not loaded maps
145145
webSettings.setOrdinal(ordinal++, map.getId());
146-
webSettings.setHiresViewDistance(map.getHiresViewDistance(), map.getId());
147-
webSettings.setLowresViewDistance(map.getLowresViewDistance(), map.getId());
146+
webSettings.setFrom(map, map.getId());
148147
}
149148
webSettings.save();
150149

BlueMapCLI/src/main/resources/bluemap-cli.conf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ renderThreadCount: 0
2424

2525
# If this is true, BlueMap might send really basic metrics reports containg only the implementation-type and the version that is being used to https://metrics.bluecolored.de/bluemap/
2626
# This allows me to track the basic usage of BlueMap and helps me stay motivated to further develop this tool! Please leave it on :)
27-
# An example report looks like this: {"implementation":"CLI","version":"%version%"}
27+
# An example report looks like this: {"implementation":"cli","version":"%version%"}
2828
metrics: true
2929

3030
# The folder where bluemap saves data-files it needs during runtime
@@ -73,6 +73,10 @@ maps: [
7373

7474
# The path to the save-folder of the world to render
7575
world: "world"
76+
77+
# The position on the world where the map will be centered if you open it.
78+
# This defaults to the world-spawn if you don't set it.
79+
#startPos: [500, -820]
7680

7781
# If this is false, BlueMap tries to omit all blocks that are not visible from above-ground.
7882
# More specific: Block-Faces that have a sunlight/skylight value of 0 are removed.

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,14 @@ public synchronized void load() throws IOException, ParseResourceException {
232232
webSettings.setAllEnabled(false);
233233
for (MapType map : maps.values()) {
234234
webSettings.setEnabled(true, map.getId());
235-
webSettings.setName(map.getName(), map.getId());
236235
webSettings.setFrom(map.getTileRenderer(), map.getId());
236+
webSettings.setFrom(map.getWorld(), map.getId());
237237
}
238238
int ordinal = 0;
239239
for (MapConfig map : config.getMapConfigs()) {
240240
if (!maps.containsKey(map.getId())) continue; //don't add not loaded maps
241241
webSettings.setOrdinal(ordinal++, map.getId());
242-
webSettings.setHiresViewDistance(map.getHiresViewDistance(), map.getId());
243-
webSettings.setLowresViewDistance(map.getLowresViewDistance(), map.getId());
242+
webSettings.setFrom(map, map.getId());
244243
}
245244
webSettings.save();
246245

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
@@ -32,6 +32,7 @@
3232
import java.util.ArrayList;
3333
import java.util.List;
3434

35+
import com.flowpowered.math.vector.Vector2i;
3536
import com.flowpowered.math.vector.Vector3i;
3637
import com.google.common.base.Preconditions;
3738

@@ -194,6 +195,8 @@ public class MapConfig implements RenderSettings {
194195
private String name;
195196
private String world;
196197

198+
private Vector2i startPos;
199+
197200
private boolean renderCaves;
198201
private float ambientOcclusion;
199202
private float lighting;
@@ -219,6 +222,8 @@ private MapConfig(ConfigurationNode node) throws IOException {
219222
this.world = node.getNode("world").getString("");
220223
if (world.isEmpty()) throw new IOException("Invalid configuration: Node maps[?].world is not defined");
221224

225+
if (!node.getNode("startPos").isVirtual()) this.startPos = ConfigUtils.readVector2i(node.getNode("startPos"));
226+
222227
this.renderCaves = node.getNode("renderCaves").getBoolean(false);
223228
this.ambientOcclusion = node.getNode("ambientOcclusion").getFloat(0.25f);
224229
this.lighting = node.getNode("lighting").getFloat(0.8f);
@@ -259,6 +264,10 @@ public String getName() {
259264
public String getWorldPath() {
260265
return world;
261266
}
267+
268+
public Vector2i getStartPos() {
269+
return startPos;
270+
}
262271

263272
public boolean isRenderCaves() {
264273
return renderCaves;

BlueMapCore/src/main/java/de/bluecolored/bluemap/core/web/WebSettings.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131

3232
import com.flowpowered.math.vector.Vector2i;
3333

34+
import de.bluecolored.bluemap.core.config.MainConfig.MapConfig;
3435
import de.bluecolored.bluemap.core.render.TileRenderer;
36+
import de.bluecolored.bluemap.core.world.World;
3537
import ninja.leaping.configurate.ConfigurationNode;
3638
import ninja.leaping.configurate.gson.GsonConfigurationLoader;
3739
import ninja.leaping.configurate.loader.ConfigurationLoader;
@@ -128,13 +130,23 @@ public void setFrom(TileRenderer tileRenderer, String mapId) {
128130
set(pointSize.getX() / 2, mapId, "lowres", "translate", "x");
129131
set(pointSize.getY() / 2, mapId, "lowres", "translate", "z");
130132
}
131-
132-
public void setHiresViewDistance(float hiresViewDistance, String mapId) {
133-
set(hiresViewDistance, mapId, "hires", "viewDistance");
133+
134+
public void setFrom(World world, String mapId) {
135+
set(world.getSpawnPoint().getX(), mapId, "startPos", "x");
136+
set(world.getSpawnPoint().getZ(), mapId, "startPos", "z");
134137
}
135138

136-
public void setLowresViewDistance(float lowresViewDistance, String mapId) {
137-
set(lowresViewDistance, mapId, "lowres", "viewDistance");
139+
public void setFrom(MapConfig mapConfig, String mapId) {
140+
Vector2i startPos = mapConfig.getStartPos();
141+
if (startPos != null) {
142+
set(startPos.getX(), mapId, "startPos", "x");
143+
set(startPos.getY(), mapId, "startPos", "z");
144+
}
145+
146+
set(mapConfig.getLowresViewDistance(), mapId, "lowres", "viewDistance");
147+
set(mapConfig.getHiresViewDistance(), mapId, "hires", "viewDistance");
148+
149+
setName(mapConfig.getName(), mapId);
138150
}
139151

140152
public void setOrdinal(int ordinal, String mapId) {

BlueMapCore/src/main/webroot/js/libs/BlueMap.js

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -81,29 +81,11 @@ export default class BlueMap {
8181
this.controls = new Controls(this.camera, this.element, this.hiresScene);
8282

8383
this.loadSettings().then(async () => {
84-
this.controls.setTileSize(this.settings[this.map]['hires']['tileSize']);
85-
86-
this.lowresTileManager = new TileManager(
87-
this,
88-
this.settings[this.map]['lowres']['viewDistance'],
89-
this.loadLowresTile,
90-
this.lowresScene,
91-
this.settings[this.map]['lowres']['tileSize'],
92-
{x: 0, z: 0}
93-
);
94-
95-
this.hiresTileManager = new TileManager(
96-
this,
97-
this.settings[this.map]['hires']['viewDistance'],
98-
this.loadHiresTile,
99-
this.hiresScene,
100-
this.settings[this.map]['hires']['tileSize'],
101-
{x: 0, z: 0}
102-
);
103-
10484
await this.loadHiresMaterial();
10585
await this.loadLowresMaterial();
10686

87+
this.changeMap(this.map);
88+
10789
this.initModules();
10890
this.start();
10991
}).catch(error => this.onLoadError(error.toString()));
@@ -119,20 +101,28 @@ export default class BlueMap {
119101
}
120102

121103
changeMap(map) {
122-
this.hiresTileManager.close();
123-
this.lowresTileManager.close();
104+
if (this.hiresTileManager !== undefined) this.hiresTileManager.close();
105+
if (this.lowresTileManager !== undefined) this.lowresTileManager.close();
124106

125107
this.map = map;
108+
109+
let startPos = {
110+
x: this.settings[this.map]["startPos"]["x"],
111+
z: this.settings[this.map]["startPos"]["z"]
112+
};
113+
126114
this.controls.setTileSize(this.settings[this.map]['hires']['tileSize']);
127115
this.controls.resetPosition();
116+
this.controls.targetPosition.set(startPos.x, this.controls.targetPosition.y, startPos.z);
117+
this.controls.position.copy(this.controls.targetPosition);
128118

129119
this.lowresTileManager = new TileManager(
130120
this,
131121
this.settings[this.map]['lowres']['viewDistance'],
132122
this.loadLowresTile,
133123
this.lowresScene,
134124
this.settings[this.map]['lowres']['tileSize'],
135-
{x: 0, z: 0}
125+
startPos
136126
);
137127

138128
this.hiresTileManager = new TileManager(
@@ -141,7 +131,7 @@ export default class BlueMap {
141131
this.loadHiresTile,
142132
this.hiresScene,
143133
this.settings[this.map]['hires']['tileSize'],
144-
{x: 0, z: 0}
134+
startPos
145135
);
146136

147137
this.lowresTileManager.update();

BlueMapCore/src/main/webroot/js/libs/TileManager.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export default class TileManager {
3737
this.scene = scene;
3838
this.tileSize = new Vector2(tileSize.x, tileSize.z);
3939

40-
this.tile = new Vector2(position.x, position.z);
40+
this.tile = new Vector2(0, 0);
41+
this.tile.set(position.x, position.z).divide(this.tileSize).floor();
4142
this.lastTile = this.tile.clone();
4243

4344
this.closed = false;

BlueMapSponge/src/main/resources/bluemap-sponge.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ maps: [
6969

7070
# The path to the save-folder of the world to render
7171
world: "world"
72+
73+
# The position on the world where the map will be centered if you open it.
74+
# This defaults to the world-spawn if you don't set it.
75+
#startPos: [500, -820]
7276

7377
# If this is false, BlueMap tries to omit all blocks that are not visible from above-ground.
7478
# More specific: Block-Faces that have a sunlight/skylight value of 0 are removed.

0 commit comments

Comments
 (0)