Skip to content

Commit 7e9ce0e

Browse files
committed
Add support for shulkers with nbt data
1 parent 58add4e commit 7e9ce0e

1 file changed

Lines changed: 39 additions & 10 deletions

File tree

src/dllmain.cpp

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,50 @@ static void ShulkerBoxBlockItem_appendFormattedHovertext(ShulkerBoxBlockItem* se
8181
}
8282

8383
static void HoverRenderer__renderHoverBox(HoverRenderer* self, MinecraftUIRenderContext* ctx, IClientInstance* client, RectangleArea* aabb, float someFloat) {
84+
// Freddie:
8485
// This is really bad code, it is relying on the fact that I have also hooked appendFormattedHovertext for items to append the item identifier
8586
// 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?
87+
//
88+
// Lucy:
89+
// No clue either but this should be more solid
8690

8791
if (self->mFilteredContent.find("shulker_box") != std::string::npos) {
88-
std::string cachedIndex = self->mFilteredContent.substr(self->mFilteredContent.size() - 7, 1);
89-
90-
try {
91-
int index = std::stoi(cachedIndex, nullptr, 16);
92-
shulkerRenderer.Render(ctx, self, index);
93-
}
94-
catch (...) {
95-
return;
92+
// Find the position right after "shulker_box§r"
93+
size_t shulkerPos = self->mFilteredContent.find("shulker_box");
94+
if (shulkerPos != std::string::npos) {
95+
// Look for the hex index after "shulker_box§r"
96+
// The pattern is: "shulker_box§r§X" where X is our hex digit
97+
size_t searchStart = shulkerPos + 11; // length of "shulker_box"
98+
99+
// Skip the "§r" that follows
100+
if (searchStart + 2 < self->mFilteredContent.size() &&
101+
self->mFilteredContent[searchStart] == '\xc2' &&
102+
self->mFilteredContent[searchStart + 1] == '\xa7' &&
103+
self->mFilteredContent[searchStart + 2] == 'r') {
104+
searchStart += 3;
105+
}
106+
107+
// Now look for our index marker "§X" where X is the hex digit
108+
if (searchStart + 2 < self->mFilteredContent.size() &&
109+
self->mFilteredContent[searchStart] == '\xc2' &&
110+
self->mFilteredContent[searchStart + 1] == '\xa7') {
111+
112+
char hexChar = self->mFilteredContent[searchStart + 2];
113+
114+
try {
115+
std::string hexStr(1, hexChar);
116+
int index = std::stoi(hexStr, nullptr, 16);
117+
118+
if (index >= 0 && index < SHULKER_CACHE_SIZE) {
119+
shulkerRenderer.Render(ctx, self, index);
120+
return;
121+
}
122+
}
123+
catch (...) {
124+
// Fall through to default rendering
125+
}
126+
}
96127
}
97-
98-
return;
99128
}
100129

101130
_HoverRenderer__renderHoverBox(self, ctx, client, aabb, someFloat);

0 commit comments

Comments
 (0)