Skip to content

Commit 9046c8b

Browse files
committed
fix a lot of player apply skin from server issues
basic hand + inventory after re-login event
1 parent a395caa commit 9046c8b

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

renderer/viewer/three/entities.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ export class Entities {
276276

277277
void this.updatePlayerSkin(playerData.id, playerData.username, playerData.uuid ?? undefined, stevePngUrl)
278278
}
279+
this.playerEntity.originalEntity = { ...playerData, name: 'player' } as SceneEntity['originalEntity']
279280

280281
// Update position and rotation
281282
if (playerData.position) {
@@ -294,6 +295,7 @@ export class Entities {
294295
disposeObject(mesh)
295296
}
296297
this.entities = {}
298+
this.currentSkinUrls = {}
297299

298300
// Clean up player entity
299301
if (this.playerEntity) {
@@ -481,6 +483,7 @@ export class Entities {
481483
}
482484

483485
uuidPerSkinUrlsCache = {} as Record<string, { skinUrl?: string, capeUrl?: string }>
486+
currentSkinUrls = {} as Record<string, string>
484487

485488
private isCanvasBlank (canvas: HTMLCanvasElement): boolean {
486489
return !canvas.getContext('2d')
@@ -517,6 +520,25 @@ export class Entities {
517520
}
518521

519522
if (typeof skinUrl !== 'string') throw new Error('Invalid skin url')
523+
524+
// Skip if same skin URL is already loaded for this entity
525+
if (this.currentSkinUrls[String(entityId)] === skinUrl) {
526+
// Still handle cape if needed
527+
if (capeUrl) {
528+
if (capeUrl === true && username) {
529+
const newCapeUrl = await loadSkinFromUsername(username, 'cape')
530+
if (!this.getPlayerObject(entityId)) return
531+
if (!newCapeUrl) return
532+
capeUrl = newCapeUrl
533+
}
534+
if (typeof capeUrl === 'string') {
535+
void this.loadAndApplyCape(entityId, capeUrl)
536+
}
537+
}
538+
return
539+
}
540+
541+
this.currentSkinUrls[String(entityId)] = skinUrl
520542
const renderEars = this.worldRenderer.worldRendererConfig.renderEars || username === 'deadmau5'
521543
void this.loadAndApplySkin(entityId, skinUrl, renderEars).then(async () => {
522544
if (capeUrl) {
@@ -1155,6 +1177,7 @@ export class Entities {
11551177
playerPerAnimation = {} as Record<number, string>
11561178
onRemoveEntity (entity: import('prismarine-entity').Entity) {
11571179
this.loadedSkinEntityIds.delete(entity.id.toString())
1180+
delete this.currentSkinUrls[entity.id.toString()]
11581181
}
11591182

11601183
updateMap (mapNumber: string | number, data: string) {

src/entities.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,10 @@ customEvents.on('gameLoaded', () => {
237237
const skinUrl = applySkinTexturesProxy(player.skinData.url)
238238
const capeUrl = applySkinTexturesProxy((player.skinData as any).capeUrl)
239239

240-
// Find entity with matching UUID and update skin
241-
let entityId = ''
242-
for (const [entId, entity] of Object.entries(bot.entities)) {
243-
if (entity.uuid === player.uuid) {
244-
entityId = entId
245-
break
246-
}
240+
void getThreeJsRendererMethods()!.updatePlayerSkin(player.entity?.id ?? '', player.username, player.uuid, skinUrl ?? true, capeUrl)
241+
if (player.entity === bot.entity) {
242+
appViewer.playerState.reactive.playerSkin = skinUrl
247243
}
248-
// even if not found, still record to cache
249-
void getThreeJsRendererMethods()!.updatePlayerSkin(entityId, player.username, player.uuid, skinUrl ?? true, capeUrl)
250244
} catch (err) {
251245
reportError(new Error('Error applying skin texture:', { cause: err }))
252246
}

0 commit comments

Comments
 (0)