feat(jui): add item switch tooltips

This commit is contained in:
Sally Knight 2026-03-26 03:10:10 +03:00 committed by Tropical
parent 11e944f78b
commit 5f5e7e7f99
2 changed files with 54 additions and 0 deletions

View file

@ -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<ItemInstance> 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

View file

@ -34,6 +34,10 @@ private:
float lastTickA;
float fAlphaIncrementPerCent;
// 4jcraft: backported item switch tooltip display from 1.6.4
int remainingHighlightTicks;
std::shared_ptr<ItemInstance> highlightingItemStack;
public:
static float currentGuiBlendFactor; // 4J added
static float currentGuiScaleFactor; // 4J added