From 1f8336334194f64e9207526dea87efc9c8137e4d Mon Sep 17 00:00:00 2001 From: Ayush Thoren Date: Sat, 7 Mar 2026 21:14:50 -0800 Subject: [PATCH] Fix stale held item appearing when switching worlds Signed-off-by: Ayush Thoren --- Minecraft.Client/ItemInHandRenderer.cpp | 8 ++++++++ Minecraft.Client/ItemInHandRenderer.h | 1 + Minecraft.Client/Minecraft.cpp | 13 +++++++++++++ 3 files changed, 22 insertions(+) diff --git a/Minecraft.Client/ItemInHandRenderer.cpp b/Minecraft.Client/ItemInHandRenderer.cpp index 782537051..f9e635893 100644 --- a/Minecraft.Client/ItemInHandRenderer.cpp +++ b/Minecraft.Client/ItemInHandRenderer.cpp @@ -930,6 +930,14 @@ void ItemInHandRenderer::tick() } +void ItemInHandRenderer::reset() +{ + selectedItem = nullptr; + lastSlot = -1; + height = 0.0f; + oHeight = 0.0f; +} + void ItemInHandRenderer::itemPlaced() { height = 0; diff --git a/Minecraft.Client/ItemInHandRenderer.h b/Minecraft.Client/ItemInHandRenderer.h index b5d840a26..0c0ac307b 100644 --- a/Minecraft.Client/ItemInHandRenderer.h +++ b/Minecraft.Client/ItemInHandRenderer.h @@ -41,6 +41,7 @@ private: int lastSlot; public: void tick(); + void reset(); void itemPlaced(); void itemUsed(); }; diff --git a/Minecraft.Client/Minecraft.cpp b/Minecraft.Client/Minecraft.cpp index 46e8497a1..727d4b963 100644 --- a/Minecraft.Client/Minecraft.cpp +++ b/Minecraft.Client/Minecraft.cpp @@ -9,6 +9,7 @@ #include "User.h" #include "Textures.h" #include "GameRenderer.h" +#include "ItemInHandRenderer.h" #include "HumanoidModel.h" #include "Options.h" #include "TexturePackRepository.h" @@ -216,6 +217,7 @@ Minecraft::Minecraft(Component *mouseComponent, Canvas *parent, MinecraftApplet m_pendingLocalConnections[i] = NULL; m_connectionFailed[i] = false; localgameModes[i]=NULL; + localitemInHandRenderers[i] = NULL; } animateTickLevel = NULL; // 4J added @@ -4226,6 +4228,17 @@ void Minecraft::setLevel(MultiPlayerLevel *level, int message /*=-1*/, shared_pt // 4J - stop update thread from processing this level, which blocks until it is safe to move on - will be re-enabled if we set the level to be non-NULL gameRenderer->DisableUpdateThread(); + if (level == NULL || player == NULL) + { + for (int i = 0; i < XUSER_MAX_COUNT; ++i) + { + if (localitemInHandRenderers[i] != NULL) + { + localitemInHandRenderers[i]->reset(); + } + } + } + for(unsigned int i = 0; i < levels.length; ++i) { // 4J We only need to save out in multiplayer is we are setting the level to NULL