Skip to content

Commit cdd8c31

Browse files
committed
fix: fix player colored username rendering, fix sometimes skin was overriden
1 parent e7c358d commit cdd8c31

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

renderer/viewer/three/entities.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ const addNametag = (entity, options: { fontFamily: string }, mesh, version: stri
141141
const canvas = getUsernameTexture(entity, options, version)
142142
const tex = new THREE.Texture(canvas)
143143
tex.needsUpdate = true
144-
let nameTag
144+
let nameTag: THREE.Object3D
145145
if (entity.nameTagFixed) {
146146
const geometry = new THREE.PlaneGeometry()
147147
const material = new THREE.MeshBasicMaterial({ map: tex })
@@ -171,6 +171,7 @@ const addNametag = (entity, options: { fontFamily: string }, mesh, version: stri
171171
nameTag.name = 'nametag'
172172

173173
mesh.add(nameTag)
174+
return nameTag
174175
}
175176
}
176177

@@ -494,6 +495,10 @@ export class Entities {
494495
// todo true/undefined doesnt reset the skin to the default one
495496
// eslint-disable-next-line max-params
496497
async updatePlayerSkin (entityId: string | number, username: string | undefined, uuidCache: string | undefined, skinUrl: string | true, capeUrl: string | true | undefined = undefined) {
498+
const isCustomSkin = skinUrl !== stevePngUrl
499+
if (isCustomSkin) {
500+
this.loadedSkinEntityIds.add(String(entityId))
501+
}
497502
if (uuidCache) {
498503
if (typeof skinUrl === 'string' || typeof capeUrl === 'string') this.uuidPerSkinUrlsCache[uuidCache] = {}
499504
if (typeof skinUrl === 'string') this.uuidPerSkinUrlsCache[uuidCache].skinUrl = skinUrl
@@ -912,20 +917,14 @@ export class Entities {
912917
mesh = wrapper
913918

914919
if (entity.username) {
915-
// todo proper colors
916-
const nameTag = new NameTagObject(fromFormattedString(entity.username).text, {
917-
font: `48px ${this.entitiesOptions.fontFamily}`,
918-
})
919-
nameTag.position.y = playerObject.position.y + playerObject.scale.y * 16 + 3
920-
nameTag.renderOrder = 1000
921-
922-
nameTag.name = 'nametag'
923-
924-
//@ts-expect-error
925-
wrapper.add(nameTag)
920+
const nametag = addNametag(entity, { fontFamily: 'mojangles' }, wrapper, this.worldRenderer.version)
921+
if (nametag) {
922+
nametag.position.y = playerObject.position.y + playerObject.scale.y * 16 + 3
923+
nametag.scale.multiplyScalar(12)
924+
}
926925
}
927926
} else {
928-
mesh = getEntityMesh(entity, this.worldRenderer, this.entitiesOptions, overrides)
927+
mesh = getEntityMesh(entity, this.worldRenderer, this.entitiesOptions, { ...overrides, customModel: entity['customModel'] })
929928
}
930929
if (!mesh) return
931930
mesh.name = 'mesh'
@@ -1181,8 +1180,7 @@ export class Entities {
11811180
const cameraPos = this.worldRenderer.cameraObject.position
11821181
const distance = mesh.position.distanceTo(cameraPos)
11831182
if (distance < MAX_DISTANCE_SKIN_LOAD && distance < (this.worldRenderer.viewDistance * 16)) {
1184-
if (this.loadedSkinEntityIds.has(entityId)) return
1185-
this.loadedSkinEntityIds.add(entityId)
1183+
if (this.loadedSkinEntityIds.has(String(entityId))) return
11861184
void this.updatePlayerSkin(entityId, mesh.playerObject.realUsername, mesh.playerObject.realPlayerUuid, true, true)
11871185
}
11881186
}

0 commit comments

Comments
 (0)