Skip to content

Commit b168ed4

Browse files
authored
Fix #1116: Use a smaller font size to fix amounts >= 100 in EMI multiblock category (#1123)
1 parent a2c913a commit b168ed4

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/client/java/aztech/modern_industrialization/compat/viewer/impl/emi/ViewerCategoryEmi.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import dev.emi.emi.api.render.EmiRenderable;
3737
import dev.emi.emi.api.stack.EmiIngredient;
3838
import dev.emi.emi.api.stack.EmiStack;
39+
import dev.emi.emi.api.widget.Bounds;
3940
import dev.emi.emi.api.widget.SlotWidget;
4041
import dev.emi.emi.api.widget.WidgetHolder;
4142
import java.util.ArrayList;
@@ -347,6 +348,31 @@ public void scrollableSlots(int cols, int rows, List<ItemStack> stacks) {
347348
public EmiIngredient getStack() {
348349
return EmiStack.of(pages.getStack(finalIndex));
349350
}
351+
352+
@Override
353+
public void drawStack(GuiGraphics draw, int mouseX, int mouseY, float delta) {
354+
var stack = pages.getStack(finalIndex);
355+
356+
Bounds bounds = getBounds();
357+
int xOff = (bounds.width() - 16) / 2;
358+
int yOff = (bounds.height() - 16) / 2;
359+
360+
// Draw count separately to handle amounts >= 100 reasonably
361+
int stackX = bounds.x() + xOff;
362+
int stackY = bounds.y() + yOff;
363+
EmiStack.of(stack, 1).render(draw, stackX, stackY, delta);
364+
var amount = Component.literal(String.valueOf(stack.getCount()));
365+
// Could use 1.0 if the count is < 100, but this looks more uniform
366+
float scale = 0.8f;
367+
368+
draw.pose().pushPose();
369+
draw.pose().translate(0, 0, 200);
370+
int tx = stackX + 17 - Math.min(14, Math.round(Minecraft.getInstance().font.width(amount) * scale)) - 1;
371+
draw.pose().translate(tx, stackY + 9, 0);
372+
draw.pose().scale(scale, scale, 1);
373+
draw.drawString(Minecraft.getInstance().font, amount, 0, 0, -1, true);
374+
draw.pose().popPose();
375+
}
350376
});
351377
}
352378
for (; index < pageSize; index++) {

0 commit comments

Comments
 (0)