diff --git a/src/main/java/com/cleanroommc/modularui/drawable/GuiDraw.java b/src/main/java/com/cleanroommc/modularui/drawable/GuiDraw.java index b345b0a12..de04d7935 100644 --- a/src/main/java/com/cleanroommc/modularui/drawable/GuiDraw.java +++ b/src/main/java/com/cleanroommc/modularui/drawable/GuiDraw.java @@ -392,6 +392,35 @@ public static void drawAmountText(int amount, String format, int x, int y, int w } } + public static void drawStandardSlotAmountText(long amount, String format, Area area) { + drawAmountText(amount, format, 1, 1, area.width - 1, area.height - 1, Alignment.BottomRight); + } + + public static void drawAmountText(long amount, String format, int x, int y, int width, int height, Alignment alignment) { + if (amount > 1 || format != null) { + String amountText = NumberFormat.AMOUNT_TEXT.format(amount); + if (format != null) { + amountText = format + amountText; + } + float scale = 1f; + if (amountText.length() == 3) { + scale = 0.8f; + } else if (amountText.length() == 4) { + scale = 0.6f; + } else if (amountText.length() > 4) { + scale = 0.5f; + } + textRenderer.setShadow(true); + textRenderer.setScale(scale); + textRenderer.setColor(Color.WHITE.main); + textRenderer.setAlignment(alignment, width, height); + textRenderer.setPos(x, y); + textRenderer.setHardWrapOnBorder(false); + textRenderer.draw(amountText); + textRenderer.setHardWrapOnBorder(true); + } + } + /*public static void drawSprite(TextureAtlasSprite sprite, float x0, float y0, float w, float h) { drawSprite(Minecraft.getMinecraft().getTextureMapBlocks(), sprite, x0, y0, w, h); } diff --git a/src/main/java/com/cleanroommc/modularui/widgets/slot/ItemSlot.java b/src/main/java/com/cleanroommc/modularui/widgets/slot/ItemSlot.java index 9eab1851b..ce2b20a12 100644 --- a/src/main/java/com/cleanroommc/modularui/widgets/slot/ItemSlot.java +++ b/src/main/java/com/cleanroommc/modularui/widgets/slot/ItemSlot.java @@ -284,7 +284,7 @@ private void drawSlot(ModularSlot slotIn) { if (amount < 0) { amount = itemstack.stackSize; } - GuiDraw.drawStandardSlotAmountText(amount, format, getArea()); + drawSlotAmountText(amount, format); int cachedCount = itemstack.stackSize; itemstack.stackSize = 1; // required to not render the amount overlay @@ -301,6 +301,10 @@ private void drawSlot(ModularSlot slotIn) { renderItem.zLevel = 0f; } + protected void drawSlotAmountText(int amount, String format) { + GuiDraw.drawStandardSlotAmountText(amount, format, getArea()); + } + @Override public @Nullable ItemStack getStackForRecipeViewer() { return this.syncHandler.getSlot().getStack();