Show player markers in the center of the current block

This commit is contained in:
James Lyne 2021-01-05 21:06:10 +00:00
parent de5be31030
commit 652a63e278
2 changed files with 11 additions and 3 deletions

View File

@ -576,9 +576,10 @@ export default {
sort: player.sort || 0, sort: player.sort || 0,
hidden: !world, hidden: !world,
location: { location: {
x: player.x || 0, //Add 0.5 to position in the middle of a block
y: player.y || 0, x: !isNaN(player.x) ? player.x + 0.5 : 0,
z: player.z || 0, y: !isNaN(player.y) ? player.y : 0,
z: !isNaN(player.z) ? player.z + 0.5 : 0,
world: world, world: world,
} }
}); });

View File

@ -75,6 +75,7 @@ export class PlayerIcon extends DivIcon {
} }
const player = this._player; const player = this._player;
let offset = 8;
this._container = document.createElement('div'); this._container = document.createElement('div');
@ -93,12 +94,15 @@ export class PlayerIcon extends DivIcon {
if (this.options.smallFace) { if (this.options.smallFace) {
this._playerImage = smallImage.cloneNode() as HTMLImageElement; this._playerImage = smallImage.cloneNode() as HTMLImageElement;
size = '16'; size = '16';
offset = 8;
} else if(this.options.showBody) { } else if(this.options.showBody) {
this._playerImage = bodyImage.cloneNode() as HTMLImageElement; this._playerImage = bodyImage.cloneNode() as HTMLImageElement;
size = 'body'; size = 'body';
offset = 16;
} else { } else {
this._playerImage = largeImage.cloneNode() as HTMLImageElement; this._playerImage = largeImage.cloneNode() as HTMLImageElement;
size = '32'; size = '32';
offset = 16;
} }
Util.getMinecraftHead(player, size).then(head => { Util.getMinecraftHead(player, size).then(head => {
@ -133,6 +137,9 @@ export class PlayerIcon extends DivIcon {
this._playerName.classList.add('playerNameNoHealth'); this._playerName.classList.add('playerNameNoHealth');
} }
this._container.style.marginTop = `-${offset}px`;
this._container.style.marginLeft = `-${offset}px`;
return this._container; return this._container;
} }