working on localized tab drawing and then committing that to the screen to help with these weird quirks.

This commit is contained in:
trunksbomb
2026-03-23 18:11:17 -04:00
parent cfcd591628
commit bc621d456e

View File

@@ -554,14 +554,15 @@ public final class BagTabOverlay {
int uOffset = (hovered || selected) ? baseWidth : 0; int uOffset = (hovered || selected) ? baseWidth : 0;
ResourceLocation baseTexture = tab.baseTexture(); ResourceLocation baseTexture = tab.baseTexture();
ResourceLocation overlayTexture = tab.overlayTexture(); ResourceLocation overlayTexture = tab.overlayTexture();
final float tintRed = red;
final float tintGreen = green;
final float tintBlue = blue;
RenderSystem.setShaderColor(red, green, blue, 1.0F); withTabLocalSpace(g, tab, () -> {
blitRotated(g, baseTexture, tab.x(), tab.y(), tab.width(), tab.height(), uOffset, 0, baseWidth, baseHeight, baseWidth * 2, baseHeight, tab.rotationDegrees()); RenderSystem.setShaderColor(tintRed, tintGreen, tintBlue, 1.0F);
blitTabLocalTexture(g, baseTexture, uOffset, 0, baseWidth, baseHeight);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
blitRotated(g, overlayTexture, tab.x(), tab.y(), tab.width(), tab.height(), uOffset, 0, baseWidth, baseHeight, baseWidth * 2, baseHeight, tab.rotationDegrees()); blitTabLocalTexture(g, overlayTexture, uOffset, 0, baseWidth, baseHeight);
g.pose().pushPose();
pushTabTransform(g, tab);
if (dragged || tab.usesFloatingArt()) { if (dragged || tab.usesFloatingArt()) {
g.fill(1, 0, baseWidth - 1, 1, 0xFF000000); g.fill(1, 0, baseWidth - 1, 1, 0xFF000000);
if (baseHeight > 2) { if (baseHeight > 2) {
@@ -578,7 +579,7 @@ public final class BagTabOverlay {
renderXIndicator(g, baseWidth - 7, Math.min(3, Math.max(0, baseHeight - 6))); renderXIndicator(g, baseWidth - 7, Math.min(3, Math.max(0, baseHeight - 6)));
} }
} }
g.pose().popPose(); });
if (tab.showFullnessIndicator() && tab.fullness() >= 0.0F) { if (tab.showFullnessIndicator() && tab.fullness() >= 0.0F) {
renderFullnessIndicator(g, tab, tab.fullness()); renderFullnessIndicator(g, tab, tab.fullness());
@@ -675,18 +676,21 @@ public final class BagTabOverlay {
private static void renderNormalFullnessIndicator(GuiGraphics g, RenderedTab tab, float fullness) { private static void renderNormalFullnessIndicator(GuiGraphics g, RenderedTab tab, float fullness) {
int color = interpolateColor(0xFF6CCBFF, 0xFF2E86FF, fullness); int color = interpolateColor(0xFF6CCBFF, 0xFF2E86FF, fullness);
g.pose().pushPose(); withTabLocalSpace(g, tab, () -> {
g.pose().translate(0.0F, 0.0F, 10_000.0F); int usableHeight = NORMAL_FILL_GAUGE_HEIGHT - 2;
int fillHeight = Math.max(0, Math.min(usableHeight, Math.round(usableHeight * fullness)));
if (tab.isVertical()) { if (tab.isVertical()) {
int gaugeX = tab.x() + Math.max(0, (tab.width() - NORMAL_FILL_GAUGE_HEIGHT) / 2); int gaugeX = Math.max(0, (tab.baseTextureWidth() - NORMAL_FILL_GAUGE_HEIGHT) / 2);
int gaugeY = tab.y() + tab.height() - NORMAL_FILL_GAUGE_WIDTH - 1; int gaugeY = tab.baseTextureHeight() - NORMAL_FILL_GAUGE_WIDTH - 1;
g.pose().pushPose(); LocalElementTransform transform = LocalElementTransform.identity()
g.pose().translate(gaugeX + (NORMAL_FILL_GAUGE_HEIGHT / 2.0F), gaugeY + (NORMAL_FILL_GAUGE_WIDTH / 2.0F), 0.0F); .translate(gaugeX, gaugeY)
g.pose().mulPose(Axis.ZP.rotationDegrees(-90.0F)); .rotate(-90.0F);
withLocalElementTransform(g, 0, 0, NORMAL_FILL_GAUGE_WIDTH, NORMAL_FILL_GAUGE_HEIGHT, transform, () -> {
g.blit( g.blit(
NORMAL_FILL_GAUGE_TEXTURE, NORMAL_FILL_GAUGE_TEXTURE,
-(NORMAL_FILL_GAUGE_WIDTH / 2), 0,
-(NORMAL_FILL_GAUGE_HEIGHT / 2), 0,
0, 0,
0, 0,
NORMAL_FILL_GAUGE_WIDTH, NORMAL_FILL_GAUGE_WIDTH,
@@ -694,65 +698,38 @@ public final class BagTabOverlay {
NORMAL_FILL_GAUGE_WIDTH, NORMAL_FILL_GAUGE_WIDTH,
NORMAL_FILL_GAUGE_HEIGHT NORMAL_FILL_GAUGE_HEIGHT
); );
int usableHeight = NORMAL_FILL_GAUGE_HEIGHT - 2;
int fillHeight = Math.max(0, Math.min(usableHeight, Math.round(usableHeight * fullness)));
if (fillHeight > 0) { if (fillHeight > 0) {
int localLeft = -(NORMAL_FILL_GAUGE_WIDTH / 2) + 1; int fillTop = 1 + (usableHeight - fillHeight);
int localTop = -(NORMAL_FILL_GAUGE_HEIGHT / 2) + 1 + (usableHeight - fillHeight); g.fill(1, fillTop, 2, 1 + usableHeight, color);
int localBottom = -(NORMAL_FILL_GAUGE_HEIGHT / 2) + 1 + usableHeight;
g.fill(localLeft, localTop, localLeft + 1, localBottom, color);
} }
g.pose().popPose(); });
g.pose().popPose();
return; return;
} }
int gaugeX = tab.x() + tab.width() - NORMAL_FILL_GAUGE_WIDTH - 1; int gaugeX = tab.baseTextureWidth() - NORMAL_FILL_GAUGE_WIDTH - 1;
int gaugeY = isFlippedHorizontalShell(tab) ? tab.y() + tab.height() - NORMAL_FILL_GAUGE_HEIGHT : tab.y(); int gaugeY = isFlippedHorizontalShell(tab) ? tab.baseTextureHeight() - NORMAL_FILL_GAUGE_HEIGHT : 0;
boolean flippedVertical = isFlippedHorizontalShell(tab); LocalElementTransform transform = LocalElementTransform.identity().translate(gaugeX, gaugeY);
if (flippedVertical) { if (isFlippedHorizontalShell(tab)) {
g.pose().pushPose(); transform = transform.mirrorVertical();
g.pose().translate(gaugeX + (NORMAL_FILL_GAUGE_WIDTH / 2.0F), gaugeY + (NORMAL_FILL_GAUGE_HEIGHT / 2.0F), 0.0F);
g.pose().scale(1.0F, -1.0F, 1.0F);
g.blit(
NORMAL_FILL_GAUGE_TEXTURE,
-(NORMAL_FILL_GAUGE_WIDTH / 2),
-(NORMAL_FILL_GAUGE_HEIGHT / 2),
0,
0,
NORMAL_FILL_GAUGE_WIDTH,
NORMAL_FILL_GAUGE_HEIGHT,
NORMAL_FILL_GAUGE_WIDTH,
NORMAL_FILL_GAUGE_HEIGHT
);
g.pose().popPose();
} else {
g.blit(
NORMAL_FILL_GAUGE_TEXTURE,
gaugeX,
gaugeY,
0,
0,
NORMAL_FILL_GAUGE_WIDTH,
NORMAL_FILL_GAUGE_HEIGHT,
NORMAL_FILL_GAUGE_WIDTH,
NORMAL_FILL_GAUGE_HEIGHT
);
} }
withLocalElementTransform(g, 0, 0, NORMAL_FILL_GAUGE_WIDTH, NORMAL_FILL_GAUGE_HEIGHT, transform, () -> {
int usableHeight = NORMAL_FILL_GAUGE_HEIGHT - 2; g.blit(
int fillHeight = Math.max(0, Math.min(usableHeight, Math.round(usableHeight * fullness))); NORMAL_FILL_GAUGE_TEXTURE,
0,
0,
0,
0,
NORMAL_FILL_GAUGE_WIDTH,
NORMAL_FILL_GAUGE_HEIGHT,
NORMAL_FILL_GAUGE_WIDTH,
NORMAL_FILL_GAUGE_HEIGHT
);
if (fillHeight > 0) { if (fillHeight > 0) {
if (flippedVertical) { int fillTop = 1 + (usableHeight - fillHeight);
int fillTop = gaugeY + 1 + (usableHeight - fillHeight); g.fill(1, fillTop, 2, 1 + usableHeight, color);
g.fill(gaugeX + 1, fillTop, gaugeX + 2, gaugeY + 1 + usableHeight, color);
} else {
int fillTop = gaugeY + 1 + (usableHeight - fillHeight);
g.fill(gaugeX + 1, fillTop, gaugeX + 2, gaugeY + 1 + usableHeight, color);
} }
} });
g.pose().popPose(); });
} }
private static int interpolateColor(int start, int end, float t) { private static int interpolateColor(int start, int end, float t) {
@@ -1079,46 +1056,22 @@ public final class BagTabOverlay {
return; return;
} }
g.pose().pushPose();
g.pose().translate(0.0F, 0.0F, 10_000.0F);
if (!tab.compact()) { if (!tab.compact()) {
withTabLocalSpace(g, tab, () -> {
LocalElementTransform transform = LocalElementTransform.identity();
if (!tab.isVertical()) { if (!tab.isVertical()) {
int bookmarkX = tab.x() + 1; transform = transform.translate(1, isFlippedHorizontalShell(tab) ? tab.baseTextureHeight() - BOOKMARK_HEIGHT : 0);
int bookmarkY = isFlippedHorizontalShell(tab) ? tab.y() + tab.height() - BOOKMARK_HEIGHT : tab.y();
if (isFlippedHorizontalShell(tab)) { if (isFlippedHorizontalShell(tab)) {
g.blit( transform = transform.mirrorVertical();
BOOKMARK_TEXTURE, }
bookmarkX,
bookmarkY,
0,
BOOKMARK_HEIGHT,
BOOKMARK_WIDTH,
-BOOKMARK_HEIGHT,
BOOKMARK_WIDTH,
BOOKMARK_HEIGHT
);
} else { } else {
transform = transform.translate(1, 0);
}
withLocalElementTransform(g, 0, 0, BOOKMARK_WIDTH, BOOKMARK_HEIGHT, transform, () -> {
g.blit( g.blit(
BOOKMARK_TEXTURE, BOOKMARK_TEXTURE,
bookmarkX,
bookmarkY,
0, 0,
0, 0,
BOOKMARK_WIDTH,
BOOKMARK_HEIGHT,
BOOKMARK_WIDTH,
BOOKMARK_HEIGHT
);
}
g.pose().popPose();
return;
}
g.pose().pushPose();
pushTabTransform(g, tab);
g.blit(
BOOKMARK_TEXTURE,
1,
0,
0, 0,
0, 0,
BOOKMARK_WIDTH, BOOKMARK_WIDTH,
@@ -1126,16 +1079,12 @@ public final class BagTabOverlay {
BOOKMARK_WIDTH, BOOKMARK_WIDTH,
BOOKMARK_HEIGHT BOOKMARK_HEIGHT
); );
g.pose().popPose(); });
g.pose().popPose(); });
return; return;
} }
g.pose().pushPose(); withTabLocalSpace(g, tab, () -> blitScaled(g, BOOKMARK_TEXTURE, 1, 0, 2, 5, 0, 0, BOOKMARK_WIDTH, BOOKMARK_HEIGHT, BOOKMARK_WIDTH, BOOKMARK_HEIGHT));
pushTabTransform(g, tab);
blitScaled(g, BOOKMARK_TEXTURE, 1, 0, 2, 5, 0, 0, BOOKMARK_WIDTH, BOOKMARK_HEIGHT, BOOKMARK_WIDTH, BOOKMARK_HEIGHT);
g.pose().popPose();
g.pose().popPose();
} }
private static void renderSelectedIndicator(GuiGraphics g, RenderedTab tab, int baseWidth, int baseHeight) { private static void renderSelectedIndicator(GuiGraphics g, RenderedTab tab, int baseWidth, int baseHeight) {
@@ -1642,6 +1591,29 @@ public final class BagTabOverlay {
g.pose().popPose(); g.pose().popPose();
} }
private static void withTabLocalSpace(GuiGraphics g, RenderedTab tab, Runnable draw) {
g.pose().pushPose();
pushTabTransform(g, tab);
draw.run();
g.pose().popPose();
}
private static void blitTabLocalTexture(GuiGraphics g, ResourceLocation texture, int u, int v, int regionWidth, int regionHeight) {
g.blit(texture, 0, 0, u, v, regionWidth, regionHeight, regionWidth * 2, regionHeight);
}
private static void withLocalElementTransform(GuiGraphics g, int x, int y, int width, int height, LocalElementTransform transform, Runnable draw) {
g.pose().pushPose();
g.pose().translate(x + transform.translateX() + (width / 2.0F), y + transform.translateY() + (height / 2.0F), 0.0F);
if (transform.rotationDegrees() != 0.0F) {
g.pose().mulPose(Axis.ZP.rotationDegrees(transform.rotationDegrees()));
}
g.pose().scale(transform.flipHorizontal() ? -1.0F : 1.0F, transform.flipVertical() ? -1.0F : 1.0F, 1.0F);
g.pose().translate(-(width / 2.0F), -(height / 2.0F), 0.0F);
draw.run();
g.pose().popPose();
}
private static void pushTabTransform(GuiGraphics g, RenderedTab tab) { private static void pushTabTransform(GuiGraphics g, RenderedTab tab) {
g.pose().translate(tab.x() + (tab.width() / 2.0F), tab.y() + (tab.height() / 2.0F), 0.0F); g.pose().translate(tab.x() + (tab.width() / 2.0F), tab.y() + (tab.height() / 2.0F), 0.0F);
g.pose().mulPose(Axis.ZP.rotationDegrees(tab.rotationDegrees())); g.pose().mulPose(Axis.ZP.rotationDegrees(tab.rotationDegrees()));
@@ -1785,6 +1757,28 @@ public final class BagTabOverlay {
} }
} }
private record LocalElementTransform(int translateX, int translateY, boolean flipHorizontal, boolean flipVertical, float rotationDegrees) {
private static LocalElementTransform identity() {
return new LocalElementTransform(0, 0, false, false, 0.0F);
}
private LocalElementTransform translate(int x, int y) {
return new LocalElementTransform(this.translateX + x, this.translateY + y, this.flipHorizontal, this.flipVertical, this.rotationDegrees);
}
private LocalElementTransform mirrorHorizontal() {
return new LocalElementTransform(this.translateX, this.translateY, !this.flipHorizontal, this.flipVertical, this.rotationDegrees);
}
private LocalElementTransform mirrorVertical() {
return new LocalElementTransform(this.translateX, this.translateY, this.flipHorizontal, !this.flipVertical, this.rotationDegrees);
}
private LocalElementTransform rotate(float degrees) {
return new LocalElementTransform(this.translateX, this.translateY, this.flipHorizontal, this.flipVertical, this.rotationDegrees + degrees);
}
}
private record PendingClick(int slot, double grabOffsetX, double grabOffsetY, boolean pinned) { private record PendingClick(int slot, double grabOffsetX, double grabOffsetY, boolean pinned) {
} }