From 058d9b86cd299b803ac91c0a96a9d82575637ad7 Mon Sep 17 00:00:00 2001 From: LabyStudio Date: Fri, 4 Feb 2022 14:38:01 +0100 Subject: [PATCH] improve mouse lock behaviour --- src/js/net/minecraft/client/GameWindow.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/js/net/minecraft/client/GameWindow.js b/src/js/net/minecraft/client/GameWindow.js index ea9bb78..dc4760b 100644 --- a/src/js/net/minecraft/client/GameWindow.js +++ b/src/js/net/minecraft/client/GameWindow.js @@ -8,6 +8,7 @@ window.GameWindow = class { this.mouseMotionX = 0; this.mouseMotionY = 0; this.mouseLocked = false; + this.actualMouseLocked = false; // Get canvas wrapper this.wrapper = document.getElementById(this.canvasWrapperId); @@ -150,18 +151,24 @@ window.GameWindow = class { } onFocusChanged() { - this.mouseLocked = document.pointerLockElement === this.canvas; + this.actualMouseLocked = document.pointerLockElement === this.canvas; } onMouseMove(event) { - this.mouseMotionX = event.movementX; - this.mouseMotionY = -event.movementY; - this.mouseX = event.clientX / this.scaleFactor; this.mouseY = event.clientY / this.scaleFactor; - if (document.pointerLockElement !== this.canvas && this.minecraft.currentScreen === null) { - this.requestFocus(); + if (document.pointerLockElement !== this.canvas) { + this.mouseLocked = false; + + if (this.minecraft.currentScreen === null) { + this.requestFocus(); + } + } + + if (this.actualMouseLocked || this.mouseLocked) { + this.mouseMotionX = event.movementX; + this.mouseMotionY = -event.movementY; } }