Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/main/java/com/cleanroommc/modularui/drawable/GuiDraw.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can reuse these long methods in int ones by casting the numbers to (long)

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down