@@ -8,7 +8,7 @@ Item::_appendFormattedHovertext _Item_appendFormattedHovertext;
88HoverRenderer::__renderHoverBox __renderHoverBox;
99
1010ShulkerRenderer shulkerRenderer;
11- ItemStack shulkerInventory[27 ];
11+ ItemStack shulkerInventory[SHULKER_CACHE_SIZE][ 27 ];
1212
1313static void Item_appendFormattedHovertext (Item* self, const ItemStackBase& itemStack, Level& level, std::string& text, uint8_t a5) {
1414 _Item_appendFormattedHovertext (self, itemStack, level, text, a5);
@@ -20,18 +20,36 @@ static void Item_appendFormattedHovertext(Item* self, const ItemStackBase& itemS
2020 uint64_t current = max - item->getDamageValue (itemStack.mUserData );
2121 text.append (fmt::format (" \n {}7Durability: {} / {}{}r" , " \xc2\xa7 " , current, max, " \xc2\xa7 " ));
2222 }
23-
23+
2424 std::string rawNameId;
2525 itemStack.getRawNameId (rawNameId);
26+
27+ if (rawNameId.find (" shulker_box" ) != std::string::npos) {
28+ // Don't append the id for shulker boxes (makes it too long)
29+ text.append (fmt::format (" \n {}8{}:{}{}r" , " \xc2\xa7 " , item->mNamespace , rawNameId, " \xc2\xa7 " ));
30+ return ;
31+ }
32+
2633 text.append (fmt::format (" \n {}8{}:{} ({}){}r" , " \xc2\xa7 " , item->mNamespace , rawNameId, item->mId , " \xc2\xa7 " ));
2734}
2835
36+ int index = 0 ;
37+
2938static void Shulker_appendFormattedHovertext (ShulkerBoxBlockItem* self, const ItemStackBase& itemStack, Level& level, std::string& text, uint8_t someBool) {
3039 // Use the appendFormattedHovertext for regular items, we don't want the list of items
3140 Item_appendFormattedHovertext (self, itemStack, level, text, someBool);
41+
42+ index++;
43+ if (index >= SHULKER_CACHE_SIZE) index = 0 ;
44+
45+ // Hide a secret index in the shulker name
46+ // We do this because appendFormattedHovertext gets called for the neightboring items so if there is a shulker
47+ // to the right of this one then its preview will get overriden, so we keep track of multiple at once using a rolling identifier
48+ text += fmt::format (" {}{:x}" , " \xc2\xa7 " , index);
49+ int thisIndex = index;
3250
3351 // Reset all the currrent item stacks
34- for (auto & itemStack : shulkerInventory) {
52+ for (auto & itemStack : shulkerInventory[index] ) {
3553 itemStack = ItemStack ();
3654 }
3755
@@ -45,15 +63,26 @@ static void Shulker_appendFormattedHovertext(ShulkerBoxBlockItem* self, const It
4563 for (int i = 0 ; i < items->size (); i++) {
4664 const CompoundTag* itemCompound = items->getCompound (i);
4765 byte slot = itemCompound->getByte (" Slot" );
48- shulkerInventory[slot]._loadItem (itemCompound);
66+ shulkerInventory[thisIndex][ slot]._loadItem (itemCompound);
4967 }
5068}
5169
5270static void _renderHoverBox (HoverRenderer* self, MinecraftUIRenderContext* ctx, IClientInstance* client, RectangleArea* aabb, float someFloat) {
5371 // This is really bad code, it is relying on the fact that I have also hooked appendFormattedHovertext for items to append the item identifier
5472 // 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?
73+
5574 if (self->mFilteredContent .find (" shulker_box" ) != std::string::npos) {
56- shulkerRenderer.Render (ctx, self);
75+ std::string cachedIndex = self->mFilteredContent .substr (self->mFilteredContent .size () - 7 , 1 );
76+
77+ try {
78+ int index = std::stoi (cachedIndex, nullptr , 16 );
79+ shulkerRenderer.Render (ctx, self, index);
80+ }
81+ catch (...) {
82+ Log::Warning (" There was an issue reading the shulker box! No id found, instead got: {}" , cachedIndex);
83+ return ;
84+ }
85+
5786 return ;
5887 }
5988
0 commit comments