Skip to content

Commit 9776d62

Browse files
committed
Only render when hovering over a shulker box && remove existing item list on shulker box hover
1 parent 97b4991 commit 9776d62

3 files changed

Lines changed: 33 additions & 21 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.12)
22
project(ItemInformation)
33
set(MOD_VERSION "1.4.0")
44

5+
56
# Define only RelWithDebInfo as the available build configuration
67
set(CMAKE_CONFIGURATION_TYPES "RelWithDebInfo" CACHE STRING "Build configurations" FORCE)
78
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo" FORCE)

include/dllmain.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <minecraft/src/common/world/Container.h>
2525
#include <minecraft/src-deps/core/resource/ResourceHelper.h>
2626
#include <minecraft/src-client/common/client/renderer/TexturePtr.h>
27+
#include <minecraft/src-client/common/client/gui/controls/renderers/HoverRenderer.h>
2728

2829
#include "ShulkerRenderer.h"
2930

src/dllmain.cpp

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,30 @@ ClientInstance* client;
55

66
ShulkerBoxBlockItem::_appendFormattedHovertext _Shulker_appendFormattedHoverText;
77
Item::_appendFormattedHovertext _Item_appendFormattedHovertext;
8+
HoverRenderer::__renderHoverBox __renderHoverBox;
89

10+
ShulkerRenderer shulkerRenderer;
911
ItemStack shulkerInventory[27];
10-
bool isHoveringShulkerbox = false;
12+
13+
static void Item_appendFormattedHovertext(Item* self, const ItemStackBase& itemStack, Level& level, std::string& text, uint8_t a5) {
14+
_Item_appendFormattedHovertext(self, itemStack, level, text, a5);
15+
Item* item = itemStack.mItem;
16+
17+
uint64_t max = item->getMaxDamage();
18+
19+
if (max != 0) {
20+
uint64_t current = max - item->getDamageValue(itemStack.mUserData);
21+
text.append(fmt::format("\n{}7Durability: {} / {}{}r", "\xc2\xa7", current, max, "\xc2\xa7"));
22+
}
23+
24+
std::string rawNameId;
25+
itemStack.getRawNameId(rawNameId);
26+
text.append(fmt::format("\n{}8{}:{} ({}){}r", "\xc2\xa7", item->mNamespace, rawNameId, item->mId, "\xc2\xa7"));
27+
}
1128

1229
static void Shulker_appendFormattedHovertext(ShulkerBoxBlockItem* self, const ItemStackBase& itemStack, Level& level, std::string& text, uint8_t someBool) {
13-
_Shulker_appendFormattedHoverText(self, itemStack, level, text, someBool);
14-
isHoveringShulkerbox = true;
30+
// Use the appendFormattedHovertext for regular items, we don't want the list of items
31+
Item_appendFormattedHovertext(self, itemStack, level, text, someBool);
1532

1633
// Reset all the currrent item stacks
1734
for (auto& itemStack : shulkerInventory) {
@@ -32,21 +49,15 @@ static void Shulker_appendFormattedHovertext(ShulkerBoxBlockItem* self, const It
3249
}
3350
}
3451

35-
static void Item_appendFormattedHovertext(Item* self, const ItemStackBase& itemStack, Level& level, std::string& text, uint8_t a5) {
36-
_Item_appendFormattedHovertext(self, itemStack, level, text, a5);
37-
isHoveringShulkerbox = false;
38-
Item* item = itemStack.mItem;
39-
40-
uint64_t max = item->getMaxDamage();
41-
42-
if (max != 0) {
43-
uint64_t current = max - item->getDamageValue(itemStack.mUserData);
44-
text.append(fmt::format("\n{}7Durability: {} / {}{}r", "\xc2\xa7", current, max, "\xc2\xa7"));
52+
static void _renderHoverBox(HoverRenderer* self, MinecraftUIRenderContext* ctx, IClientInstance* client, RectangleArea* aabb, float someFloat) {
53+
// This is really bad code, it is relying on the fact that I have also hooked appendFormattedHovertext for items to append the item identifier
54+
// I have no idea where the currently hovered item is stored in the game! I can't find any references to it, so it might be set in some weird place?
55+
if (self->mText.find("shulker_box") != std::string::npos) {
56+
shulkerRenderer.Render(ctx);
57+
return;
4558
}
4659

47-
std::string rawNameId;
48-
itemStack.getRawNameId(rawNameId);
49-
text.append(fmt::format("\n{}8{}:{} ({}){}r", "\xc2\xa7", item->mNamespace, rawNameId, item->mId, "\xc2\xa7"));
60+
__renderHoverBox(self, ctx, client, aabb, someFloat);
5061
}
5162

5263
ModFunction void Initialize(const char* gameVersion, InputManager * inputManager) {
@@ -61,12 +72,11 @@ ModFunction void Initialize(const char* gameVersion, InputManager * inputManager
6172
SigScan("40 55 53 56 57 41 54 41 55 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 45 ? 49 8B F1 4C 89 44 24 ? 4C 8B F2 48 8B D9"),
6273
&Item_appendFormattedHovertext, reinterpret_cast<void**>(&_Item_appendFormattedHovertext)
6374
);
64-
}
6575

66-
ShulkerRenderer shulkerRenderer;
67-
68-
ModFunction void OnRenderUI(ScreenView* screenView, UIRenderContext* ctx) {
69-
shulkerRenderer.Render(ctx);
76+
hookManager.CreateHook(
77+
SigScan("48 8B C4 48 89 58 ? 48 89 70 ? 48 89 78 ? 4C 89 70 ? 55 48 8D 68 ? 48 81 EC ? ? ? ? 0F 29 70 ? 0F 29 78 ? 44 0F 29 40 ? 49 8B D9"),
78+
&_renderHoverBox, reinterpret_cast<void**>(&__renderHoverBox)
79+
);
7080
}
7181

7282
ModFunction void Shutdown() {

0 commit comments

Comments
 (0)