From 5f5e7e7f99fb87daf77524495825e5d988c62a3b Mon Sep 17 00:00:00 2001 From: Sally Knight Date: Thu, 26 Mar 2026 03:10:10 +0300 Subject: [PATCH] feat(jui): add item switch tooltips --- Minecraft.Client/UI/Gui.cpp | 50 +++++++++++++++++++++++++++++++++++++ Minecraft.Client/UI/Gui.h | 4 +++ 2 files changed, 54 insertions(+) diff --git a/Minecraft.Client/UI/Gui.cpp b/Minecraft.Client/UI/Gui.cpp index 8d9d12071..728277092 100644 --- a/Minecraft.Client/UI/Gui.cpp +++ b/Minecraft.Client/UI/Gui.cpp @@ -56,6 +56,10 @@ Gui::Gui(Minecraft* minecraft) { tbr = 1.0f; fAlphaIncrementPerCent = 255.0f / 100.0f; + // 4jcraft: backported item switch tooltip display from 1.6.4 + remainingHighlightTicks = 0; + highlightingItemStack = nullptr; + this->minecraft = minecraft; lastTickA = 0.0f; @@ -816,6 +820,31 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) { } #if RENDER_HUD + // 4jcraft: backported item switch tooltip display from 1.6.4 + if (remainingHighlightTicks > 0 && highlightingItemStack != nullptr) { + std::wstring displayName = highlightingItemStack->getHoverName(); + int x = (screenWidth - font->width(displayName)) / 2; + int y = screenHeight - 89; + + if (!minecraft->gameMode->canHurtPlayer()) { + y += 14; + } + + int alpha = (int)((float)remainingHighlightTicks * 256.0f / 10.0f); + if (alpha > 255) alpha = 255; + if (alpha > 0) { + glPushMatrix(); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + int color = 0xFFFFFF | (alpha << 24); + font->drawShadow(displayName, x, y, color); + + glDisable(GL_BLEND); + glPopMatrix(); + } + } + // Moved so the opacity blend is applied to it if (bDisplayGui && minecraft->gameMode->hasExperience() && minecraft->player->experienceLevel > 0) { @@ -1334,6 +1363,27 @@ void Gui::tick() { if (overlayMessageTime > 0) overlayMessageTime--; tickCount++; + // 4jcraft: backported item switch tooltip display from 1.6.4 + if (minecraft->player != nullptr) { + std::shared_ptr currentItem = + minecraft->player->inventory->getSelected(); + + if (currentItem == nullptr) { + remainingHighlightTicks = 0; + } else if (highlightingItemStack != nullptr && + currentItem->id == highlightingItemStack->id && + currentItem->sameItemWithTags(highlightingItemStack) && + (currentItem->isDamageableItem() || + currentItem->getDamageValue() == + highlightingItemStack->getDamageValue())) { + if (remainingHighlightTicks > 0) --remainingHighlightTicks; + } else { + remainingHighlightTicks = 40; + } + + highlightingItemStack = currentItem; + } + for (int iPad = 0; iPad < XUSER_MAX_COUNT; iPad++) { // 4J Stu - Fix for #10929 - MP LAB: Network Disconnects: Host does not // receive an error message stating the client left the game when diff --git a/Minecraft.Client/UI/Gui.h b/Minecraft.Client/UI/Gui.h index 81ee2b5f8..2ced840c3 100644 --- a/Minecraft.Client/UI/Gui.h +++ b/Minecraft.Client/UI/Gui.h @@ -34,6 +34,10 @@ private: float lastTickA; float fAlphaIncrementPerCent; + // 4jcraft: backported item switch tooltip display from 1.6.4 + int remainingHighlightTicks; + std::shared_ptr highlightingItemStack; + public: static float currentGuiBlendFactor; // 4J added static float currentGuiScaleFactor; // 4J added