From 2ae2d9ff1bca9d17cd286fefd4d5575ea45a3437 Mon Sep 17 00:00:00 2001 From: acth2 Date: Sat, 7 Mar 2026 01:02:52 +0100 Subject: [PATCH] Disable input instead of showing an empty gui --- Minecraft.Client/Minecraft.cpp | 10 ++++++++-- .../Windows64/KeyboardMouseInput.cpp | 6 ++++++ .../Windows64/KeyboardMouseInput.h | 5 +++++ Minecraft.World/Player.cpp | 18 +++--------------- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/Minecraft.Client/Minecraft.cpp b/Minecraft.Client/Minecraft.cpp index 76c3b779d..7b1bb9ae9 100644 --- a/Minecraft.Client/Minecraft.cpp +++ b/Minecraft.Client/Minecraft.cpp @@ -2257,6 +2257,7 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures) int iPad=player->GetXboxPad(); //OutputDebugString("Minecraft::tick\n"); + //4J-PB - only tick this player's stats stats[iPad]->tick(iPad); @@ -2305,6 +2306,7 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures) * progressRenderer.progressStagePercentage(0); } else { * serverConnection.tick(); serverConnection.sendPosition(player); } } */ + if (screen == NULL && player != NULL ) { if (player->getHealth() <= 0 && !ui.GetMenuDisplayed(iPad) ) @@ -2313,7 +2315,7 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures) } else if (player->isSleeping() && level != NULL && level->isClientSide) { - // setScreen(new InBedChatScreen()); // 4J - TODO put back in + //setScreen(new InBedChatScreen()); // 4J - TODO put back in } } else if (screen != NULL && (dynamic_cast(screen)!=NULL) && !player->isSleeping()) @@ -2350,7 +2352,11 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures) #ifdef _WINDOWS64 if (!g_KBMInput.IsMouseGrabbed() && g_KBMInput.IsWindowFocused()) { - g_KBMInput.SetMouseGrabbed(true); + g_KBMInput.SetMouseGrabbed(false); + } + + if (screen == NULL && !g_KBMInput.IsMouseGrabbed() && g_KBMInput.IsWindowFocused()) { + g_KBMInput.SetMouseGrabbed(true); } #endif // 4J-PB - add some tooltips if required diff --git a/Minecraft.Client/Windows64/KeyboardMouseInput.cpp b/Minecraft.Client/Windows64/KeyboardMouseInput.cpp index 3a98a0987..c66cd611c 100644 --- a/Minecraft.Client/Windows64/KeyboardMouseInput.cpp +++ b/Minecraft.Client/Windows64/KeyboardMouseInput.cpp @@ -50,6 +50,7 @@ void KeyboardMouseInput::Init() m_mouseWheelAccum = 0; m_mouseWheelConsumed = false; m_mouseGrabbed = false; + m_mouseActive = true; m_cursorHiddenForUI = false; m_windowFocused = true; m_hasInput = false; @@ -200,10 +201,15 @@ int KeyboardMouseInput::GetMouseWheel() void KeyboardMouseInput::OnRawMouseDelta(int dx, int dy) { + if (!m_mouseActive) + return; + m_mouseDeltaAccumX += dx; m_mouseDeltaAccumY += dy; } + + bool KeyboardMouseInput::IsKeyDown(int vkCode) const { if (vkCode == VK_SHIFT || vkCode == VK_CONTROL || vkCode == VK_MENU) diff --git a/Minecraft.Client/Windows64/KeyboardMouseInput.h b/Minecraft.Client/Windows64/KeyboardMouseInput.h index 0f14dfa1f..5520e0745 100644 --- a/Minecraft.Client/Windows64/KeyboardMouseInput.h +++ b/Minecraft.Client/Windows64/KeyboardMouseInput.h @@ -84,6 +84,9 @@ public: void SetScreenCursorHidden(bool hidden) { m_screenWantsCursorHidden = hidden; } bool IsScreenCursorHidden() const { return m_screenWantsCursorHidden; } + void SetActiveMouse(bool active) { m_mouseActive = active; } + bool IsActiveMouse() { return m_mouseActive; } + // Text input: buffer characters typed while the native keyboard scene is open void OnChar(wchar_t c); bool ConsumeChar(wchar_t &outChar); @@ -133,6 +136,8 @@ private: bool m_kbmActive; + bool m_mouseActive; + bool m_screenWantsCursorHidden; static const int CHAR_BUFFER_SIZE = 32; diff --git a/Minecraft.World/Player.cpp b/Minecraft.World/Player.cpp index 6e82a1224..df994e5bc 100644 --- a/Minecraft.World/Player.cpp +++ b/Minecraft.World/Player.cpp @@ -368,13 +368,6 @@ void Player::tick() foodData.tick(dynamic_pointer_cast(shared_from_this())); } - #ifdef _WINDOWS64 - if (g_KBMInput.IsKeyDown(VK_LSHIFT) && this->isSleeping()) - { - stopSleepInBed(true, true, false); - } - #endif - // 4J Stu Debugging if (!level->isClientSide) { @@ -1865,10 +1858,7 @@ Player::BedSleepingResult Player::startSleepInBed(int x, int y, int z, bool bTes setPos(x + .5f, y + 15.0f / 16.0f, z + .5f); } m_isSleeping = true; - - #ifdef _WINDOWS64 - Minecraft::GetInstance()->setScreen(new Screen()); - #endif + g_KBMInput.SetActiveMouse(false); sleepCounter = 0; bedPosition = new Pos(x, y, z); @@ -1940,6 +1930,8 @@ void Player::stopSleepInBed(bool forcefulWakeUp, bool updateLevelList, bool save } m_isSleeping = false; + g_KBMInput.SetActiveMouse(true); + if (!level->isClientSide && updateLevelList) { level->updateSleepingPlayerList(); @@ -1956,10 +1948,6 @@ void Player::stopSleepInBed(bool forcefulWakeUp, bool updateLevelList, bool save { setRespawnPosition(bedPosition, false); } - - #ifdef _WINDOWS64 - Minecraft::GetInstance()->setScreen(nullptr); - #endif }