Skip to content

Commit 9833447

Browse files
committed
Use actual inventory item slot texture
1 parent 9776d62 commit 9833447

3 files changed

Lines changed: 26 additions & 10 deletions

File tree

include/ShulkerRenderer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99

1010
class ShulkerRenderer {
1111
public:
12-
void Render(UIRenderContext* ctx);
12+
void Render(UIRenderContext* ctx, std::string& hoverText);
1313
};

src/ShulkerRenderer.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@ static HashedString flushString(0xA99285D21E94FC80, "ui_flush");
44

55
// Texture loading
66
static auto itemSlotTexture = std::make_unique<mce::TexturePtr>();
7-
static ResourceLocation itemSlotLocation("textures/ui/hotbar_0");
7+
static ResourceLocation itemSlotLocation("textures/gui/gui");
88
bool hasLoadedTexture = false;
99

1010
// Slot sizing
1111
float slotSize = 20.f;
1212
float borderSize = (slotSize - 16.f) / 2;
1313

14+
// Uv positions
15+
glm::tvec2<float> itemSlotUvPos(188.0f / 256.0f, 184.0f / 256.0f);
16+
glm::tvec2<float> itemSlotUvSize(22.0f / 256.0f, 22.0f / 256.0f);
17+
1418
extern ItemStack shulkerInventory[27];
1519

16-
void ShulkerRenderer::Render(UIRenderContext* ctx) {
20+
mce::Color panelBackground(27.0f / 255.0f, 12.0f / 255.0f, 27.0f / 255.0f, 1.0f);
21+
22+
void ShulkerRenderer::Render(UIRenderContext* ctx, std::string& hoverText) {
1723
if (ctx == nullptr || ctx->mClient->getLocalPlayer() == nullptr) return;
1824

1925
// Only load inventory resources once
@@ -22,18 +28,24 @@ void ShulkerRenderer::Render(UIRenderContext* ctx) {
2228
hasLoadedTexture = true;
2329
}
2430

31+
float textHeight = 20.0f;
32+
float panelWidth = slotSize * 9;
33+
float panelHeight = slotSize * 3 + textHeight;
34+
35+
RectangleArea background = {0.0f, panelWidth, 0.0f, panelHeight};
36+
ctx->drawRectangle(&background, &panelBackground, 1.0f, 1);
37+
2538
// Draw the item slots
2639
for (int x = 0; x < 9; x++) {
2740
for (int y = 0; y < 3; y++) {
28-
glm::tvec2<float> vec2zero(0.0f, 0.0f);
29-
glm::tvec2<float> vec2one(1.0f, 1.0f);
3041
glm::tvec2<float> size(slotSize, slotSize);
31-
glm::tvec2<float> position(slotSize * x, slotSize * y);
42+
glm::tvec2<float> position(slotSize * x, slotSize * y + textHeight);
3243

33-
ctx->drawImage(*itemSlotTexture, &position, &size, &vec2zero, &vec2one, 0);
44+
ctx->drawImage(*itemSlotTexture, &position, &size, &itemSlotUvPos, &itemSlotUvSize, 0);
3445
}
3546
}
3647

48+
// It's possible to tint the background here
3749
ctx->flushImages(mce::Color::WHITE, 1.0f, flushString);
3850

3951
// Draw the item icons
@@ -47,7 +59,7 @@ void ShulkerRenderer::Render(UIRenderContext* ctx) {
4759
float xPos = (x * slotSize) + borderSize;
4860
float yPos = (y * slotSize) + borderSize;
4961

50-
renderCtxPtr.itemRenderer->renderGuiItemNew(&renderCtxPtr, itemStack, 0, xPos, yPos, false, 1.f, 1.f, 1.f);
62+
renderCtxPtr.itemRenderer->renderGuiItemNew(&renderCtxPtr, itemStack, 0, xPos, yPos + textHeight, false, 1.f, 1.f, 1.f);
5163
}
5264
}
5365

@@ -68,7 +80,7 @@ void ShulkerRenderer::Render(UIRenderContext* ctx) {
6880
if (itemStack->mItem == nullptr) continue;
6981
if (itemStack->count == 1) continue;
7082

71-
float top = (y * slotSize) + borderSize;
83+
float top = (y * slotSize) + borderSize + textHeight;
7284
float bottom = top + 16.f;
7385

7486
float left = (x * slotSize) + borderSize;
@@ -82,4 +94,8 @@ void ShulkerRenderer::Render(UIRenderContext* ctx) {
8294
}
8395

8496
ctx->flushText(0.0f);
97+
98+
RectangleArea rect = { 0.0f, 0.0f, 0.0f, 0.0f };
99+
ctx->drawDebugText(&rect, &hoverText, &mce::Color::WHITE, 1.0f, ui::Left, &textData, &caretData);
100+
ctx->flushText(0.0f);
85101
}

src/dllmain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static void _renderHoverBox(HoverRenderer* self, MinecraftUIRenderContext* ctx,
5353
// This is really bad code, it is relying on the fact that I have also hooked appendFormattedHovertext for items to append the item identifier
5454
// 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?
5555
if (self->mText.find("shulker_box") != std::string::npos) {
56-
shulkerRenderer.Render(ctx);
56+
shulkerRenderer.Render(ctx, self->mText);
5757
return;
5858
}
5959

0 commit comments

Comments
 (0)