From 652a63e27828ce4b1671f705145f23fcc3d86234 Mon Sep 17 00:00:00 2001 From: James Lyne Date: Tue, 5 Jan 2021 21:06:10 +0000 Subject: [PATCH] Show player markers in the center of the current block --- src/api.ts | 7 ++++--- src/leaflet/icon/PlayerIcon.ts | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/api.ts b/src/api.ts index bd188f2..2017eda 100644 --- a/src/api.ts +++ b/src/api.ts @@ -576,9 +576,10 @@ export default { sort: player.sort || 0, hidden: !world, location: { - x: player.x || 0, - y: player.y || 0, - z: player.z || 0, + //Add 0.5 to position in the middle of a block + x: !isNaN(player.x) ? player.x + 0.5 : 0, + y: !isNaN(player.y) ? player.y : 0, + z: !isNaN(player.z) ? player.z + 0.5 : 0, world: world, } }); diff --git a/src/leaflet/icon/PlayerIcon.ts b/src/leaflet/icon/PlayerIcon.ts index a064f47..38da1e5 100644 --- a/src/leaflet/icon/PlayerIcon.ts +++ b/src/leaflet/icon/PlayerIcon.ts @@ -75,6 +75,7 @@ export class PlayerIcon extends DivIcon { } const player = this._player; + let offset = 8; this._container = document.createElement('div'); @@ -93,12 +94,15 @@ export class PlayerIcon extends DivIcon { if (this.options.smallFace) { this._playerImage = smallImage.cloneNode() as HTMLImageElement; size = '16'; + offset = 8; } else if(this.options.showBody) { this._playerImage = bodyImage.cloneNode() as HTMLImageElement; size = 'body'; + offset = 16; } else { this._playerImage = largeImage.cloneNode() as HTMLImageElement; size = '32'; + offset = 16; } Util.getMinecraftHead(player, size).then(head => { @@ -133,6 +137,9 @@ export class PlayerIcon extends DivIcon { this._playerName.classList.add('playerNameNoHealth'); } + this._container.style.marginTop = `-${offset}px`; + this._container.style.marginLeft = `-${offset}px`; + return this._container; }