Fix position desync causing item interaction failures

This commit is contained in:
Jage9
2026-02-24 21:01:21 -05:00
parent 297f1c0c1a
commit 4ea5419d30
7 changed files with 103 additions and 11 deletions

View File

@@ -1094,8 +1094,7 @@ function updateTeleport(): void {
const completionStatus = activeTeleport.completionStatus;
state.player.x = activeTeleport.targetX;
state.player.y = activeTeleport.targetY;
signaling.send({ type: 'update_position', x: activeTeleport.targetX, y: activeTeleport.targetY });
signaling.send({ type: 'teleport_complete' });
signaling.send({ type: 'teleport_complete', x: activeTeleport.targetX, y: activeTeleport.targetY });
activeTeleport = null;
stopTeleportLoopAudio();
persistPlayerPosition();

View File

@@ -140,6 +140,11 @@ export function createOnMessageHandler(deps: MessageHandlerDeps): (message: Inco
}
case 'update_position': {
if (message.id === deps.state.player.id) {
deps.state.player.x = message.x;
deps.state.player.y = message.y;
break;
}
const peer = deps.state.peers.get(message.id);
const prevX = peer?.x ?? message.x;
const prevY = peer?.y ?? message.y;

View File

@@ -225,7 +225,7 @@ export type IncomingMessage = z.infer<typeof incomingMessageSchema>;
export type OutgoingMessage =
| { type: 'signal'; targetId: string; sdp?: RTCSessionDescriptionInit; ice?: RTCIceCandidateInit }
| { type: 'update_position'; x: number; y: number }
| { type: 'teleport_complete' }
| { type: 'teleport_complete'; x: number; y: number }
| { type: 'update_nickname'; nickname: string }
| { type: 'chat_message'; message: string }
| { type: 'ping'; clientSentAt: number }