Skip to content

feat: Detect when player is within map bounds #692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/webapp/src/components/Menu/MarkerItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default {

if (this.marker.type === "player") {

if (this.marker.foreign) {
if (this.marker.foreign || this.marker.outOfBounds) {
let matchingMap = await this.$bluemap.findPlayerMap(this.marker.playerUuid);
if (!matchingMap) return;

Expand Down
16 changes: 13 additions & 3 deletions common/webapp/src/js/BlueMapApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export class BlueMapApp {
let player = this.mapViewer.controlsManager.controls?.data.followingPlayer;

if (this.mapViewer.map && player) {
if (player.foreign){
if (player.foreign || player.outOfBounds) {

let matchingMap = await this.findPlayerMap(player.playerUuid)
if (matchingMap) {
Expand All @@ -228,10 +228,20 @@ export class BlueMapApp {
for (let map of this.maps) {
let playerData = await this.loadPlayerData(map);
if (!Array.isArray(playerData.players)) continue;
const [minX, maxX] = map.data?.bounds?.x ?? [];
const [minY, maxY] = map.data?.bounds?.y ?? [];
const [minZ, maxZ] = map.data?.bounds?.z ?? [];
for (let p of playerData.players) {
if (p.uuid === playerUuid && !p.foreign) {
matchingMap = map;
break;
const pos = p.position || {};
const { x, y, z } = pos;
// if any coordinate is missing or within its respective map bounds, consider it in bounds
if ((x == null || ((minX == null || x >= minX) && (maxX == null || x <= maxX))) &&
(y == null || ((minY == null || y >= minY) && (maxY == null || y <= maxY))) &&
(z == null || ((minZ == null || z >= minZ) && (maxZ == null || z <= maxZ)))) {
matchingMap = map;
break;
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions common/webapp/src/js/map/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export class Map {
texturesUrl: mapDataRoot + "/textures.json",
name: id,
startPos: {x: 0, z: 0},
bounds: {
x: null,
y: null,
z: null
},
skyColor: new Color(),
voidColor: new Color(0, 0, 0),
ambientLight: 0,
Expand Down Expand Up @@ -169,6 +174,16 @@ export class Map {

this.data.startPos = {...this.data.startPos, ...vecArrToObj(worldSettings.startPos, true)};

if (worldSettings.bounds) {
const currentBounds = this.data.bounds;
['x', 'y', 'z'].forEach(coordinate => {
const boundsRange = worldSettings.bounds[coordinate];
if (Array.isArray(boundsRange) && boundsRange.length === 2) {
currentBounds[coordinate] = [...boundsRange];
}
});
}

if (worldSettings.skyColor && worldSettings.skyColor.length >= 3) {
this.data.skyColor.setRGB(
worldSettings.skyColor[0],
Expand Down
19 changes: 19 additions & 0 deletions common/webapp/src/js/markers/PlayerMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export class PlayerMarker extends Marker {
this.playerHeadElement.src = "assets/steve.png";
}, {once: true});

this.map = window.bluemap.mapViewer.map;

this.add(this.elementObject);
}

Expand Down Expand Up @@ -94,6 +96,7 @@ export class PlayerMarker extends Marker {
* uuid: string,
* name: string,
* foreign: boolean,
* outOfBounds: boolean,
* position: {x: number, y: number, z: number},
* rotation: {yaw: number, pitch: number, roll: number}
* }}
Expand Down Expand Up @@ -155,6 +158,22 @@ export class PlayerMarker extends Marker {

// update world
this.data.foreign = markerData.foreign;

// update outOfBounds based on current world bounds
if (this.map && this.map.data && this.map.data.bounds) {
const bounds = this.map.data.bounds;
const currentPos = this.position;
this.data.outOfBounds = (
currentPos.x < bounds.x[0] ||
currentPos.x > bounds.x[1] ||
currentPos.y < bounds.y[0] ||
currentPos.y > bounds.y[1] ||
currentPos.z < bounds.z[0] ||
currentPos.z > bounds.z[1]
);
} else {
this.data.outOfBounds = false;
}
}

dispose() {
Expand Down
4 changes: 2 additions & 2 deletions common/webapp/src/js/markers/PlayerMarkerSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ export class PlayerMarkerSet extends MarkerSet {
// update
marker.updateFromData(markerData);

// hide if from different world
marker.visible = !markerData.foreign;
// hide if from different world or out of bounds
marker.visible = !markerData.foreign && !marker.data.outOfBounds;

return marker;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package de.bluecolored.bluemap.core.map;

import com.flowpowered.math.vector.Vector2i;
import com.flowpowered.math.vector.Vector3i;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
Expand Down Expand Up @@ -71,6 +72,15 @@ public JsonElement serialize(BmMap map, Type typeOfSrc, JsonSerializationContext
.orElse(map.getWorld().getSpawnPoint().toVector2(true));
root.add("startPos", context.serialize(startPos));

// bounds
JsonObject bounds = new JsonObject();
Vector3i min = map.getMapSettings().getMinPos();
Vector3i max = map.getMapSettings().getMaxPos();
bounds.add("x", context.serialize(new int[] { min.getX(), max.getX() }));
bounds.add("y", context.serialize(new int[] { min.getY(), max.getY() }));
bounds.add("z", context.serialize(new int[] { min.getZ(), max.getZ() }));
root.add("bounds", bounds);

// skyColor
Color skyColor = new Color().parse(map.getMapSettings().getSkyColor());
root.add("skyColor", context.serialize(skyColor));
Expand Down
Loading