Compare commits

...
1 Commits
Author SHA1 Message Date
6e6b8539f3 FluidStack rendered text unification (#1169)
Co-authored-by: Connor Colenso <colen@CONNORSPC>
Co-authored-by: slprime <[email protected]>
2026-11-27 13:37:06 +01:00
7 changed files with 35 additions and 48 deletions

No files matched your search

@@ -26,7 +26,6 @@ import codechicken.nei.recipe.Recipe;
import codechicken.nei.recipe.Recipe.RecipeId; import codechicken.nei.recipe.Recipe.RecipeId;
import codechicken.nei.recipe.RecipeInfo; import codechicken.nei.recipe.RecipeInfo;
import codechicken.nei.recipe.StackInfo; import codechicken.nei.recipe.StackInfo;
import codechicken.nei.util.ReadableNumberConverter;
public class ItemCraftablesPanel public class ItemCraftablesPanel
extends AbstractSubpanel<ItemsGrid<ItemCraftablesPanel.CraftablesGridSlot, MouseContext>> { extends AbstractSubpanel<ItemsGrid<ItemCraftablesPanel.CraftablesGridSlot, MouseContext>> {
@@ -36,12 +35,15 @@ public class ItemCraftablesPanel
protected final long realAmount; protected final long realAmount;
protected final boolean isFluidDisplay; protected final boolean isFluidDisplay;
protected final RecipeId recipeId; protected final RecipeId recipeId;
protected final ItemStack drawnItemStack;
public CraftablesGridSlot(int slotIndex, int itemIndex, ItemStack itemStack, RecipeId recipeId) { public CraftablesGridSlot(int slotIndex, int itemIndex, ItemStack itemStack, RecipeId recipeId) {
super(slotIndex, itemIndex, itemStack); super(slotIndex, itemIndex, itemStack);
this.realAmount = StackInfo.getAmountLong(itemStack); this.realAmount = StackInfo.getAmountLong(itemStack);
this.isFluidDisplay = StackInfo.isFluidDisplayItem(itemStack); this.isFluidDisplay = StackInfo.isFluidDisplayItem(itemStack);
this.recipeId = recipeId; this.recipeId = recipeId;
final ItemStack empty = this.isFluidDisplay ? StackInfo.withAmount(itemStack, 0) : null;
this.drawnItemStack = empty != null ? empty : itemStack;
} }
@Override @Override
@@ -49,6 +51,11 @@ public class ItemCraftablesPanel
return this.recipeId; return this.recipeId;
} }
@Override
public void drawItem(Rectangle4i rect) {
super.drawItem(this.drawnItemStack, rect);
}
@Override @Override
public <M extends MouseContext> void afterDraw(Rectangle4i rect, M mouseContext) { public <M extends MouseContext> void afterDraw(Rectangle4i rect, M mouseContext) {
drawStackSize(rect); drawStackSize(rect);
@@ -59,17 +66,7 @@ public class ItemCraftablesPanel
if (stackSize > 1) { if (stackSize > 1) {
final float panelFactor = (rect.w - 2) / (DEFAULT_SLOT_SIZE - 2); final float panelFactor = (rect.w - 2) / (DEFAULT_SLOT_SIZE - 2);
String amountString = ""; final String amountString = NEIClientUtils.formatSlotAmount(stackSize, this.isFluidDisplay);
if (stackSize < 10_000) {
amountString = String.valueOf(stackSize);
} else {
amountString = ReadableNumberConverter.INSTANCE.toWideReadableForm(stackSize);
}
if (this.isFluidDisplay) {
amountString += "L";
}
NEIClientUtils.drawNEIOverlayText( NEIClientUtils.drawNEIOverlayText(
amountString, amountString,
@@ -68,10 +68,9 @@ public class ItemsTooltipLineHandler implements ITooltipLineHandler {
protected void drawAmount(Rectangle4i rect, ItemStack stack, long amount) { protected void drawAmount(Rectangle4i rect, ItemStack stack, long amount) {
final AmountText amountText = this.cache.computeIfAbsent(stack, key -> { final AmountText amountText = this.cache.computeIfAbsent(stack, key -> {
final boolean isFluidDisplay = StackInfo.isFluidDisplayItem(key); final boolean isFluidDisplay = StackInfo.isFluidDisplayItem(key);
final String text = formatAmount(key, amount);
return new AmountText( return new AmountText(
isFluidDisplay && !text.isEmpty() ? text + "L" : text, formatAmount(key, amount),
isFluidDisplay ? Alignment.BottomLeft : Alignment.BottomRight); isFluidDisplay ? Alignment.BottomLeft : Alignment.BottomRight);
}); });
@@ -81,7 +80,7 @@ public class ItemsTooltipLineHandler implements ITooltipLineHandler {
} }
protected String formatAmount(ItemStack stack, long amount) { protected String formatAmount(ItemStack stack, long amount) {
return amount == 0 ? "" : ReadableNumberConverter.INSTANCE.toWideReadableForm(amount); return amount == 0 ? "" : NEIClientUtils.formatSlotAmount(amount, StackInfo.isFluidDisplayItem(stack));
} }
} }
@@ -53,6 +53,7 @@ import org.lwjgl.opengl.GL11;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.gtnewhorizon.gtnhlib.util.numberformatting.NumberFormatUtil; import com.gtnewhorizon.gtnhlib.util.numberformatting.NumberFormatUtil;
import com.gtnewhorizon.gtnhlib.util.numberformatting.options.CompactOptions;
import codechicken.lib.gui.GuiDraw; import codechicken.lib.gui.GuiDraw;
import codechicken.lib.inventory.InventoryRange; import codechicken.lib.inventory.InventoryRange;
@@ -65,6 +66,7 @@ import codechicken.nei.api.ItemInfo;
import codechicken.nei.recipe.GuiOverlayButton.ItemOverlayState; import codechicken.nei.recipe.GuiOverlayButton.ItemOverlayState;
import codechicken.nei.recipe.StackInfo; import codechicken.nei.recipe.StackInfo;
import codechicken.nei.util.NEIKeyboardUtils; import codechicken.nei.util.NEIKeyboardUtils;
import codechicken.nei.util.ReadableNumberConverter;
public class NEIClientUtils extends NEIServerUtils { public class NEIClientUtils extends NEIServerUtils {
@@ -154,6 +156,23 @@ public class NEIClientUtils extends NEIServerUtils {
return getDecimalFormat().format(aNumber) + " L"; return getDecimalFormat().format(aNumber) + " L";
} }
/** Only loaded when GTNHLib is, since CompactOptions comes from it. */
private static final class FluidSlotAmountFormat {
private static final CompactOptions OPTIONS = new CompactOptions().setCompactThreshold(10_000)
.setDecimalPlaces(1).setRoundingMode(RoundingMode.DOWN);
}
/** The amount drawn over a slot. Fluids use GTNHLib's compact formatting when it's loaded and have no unit. */
public static String formatSlotAmount(long amount, boolean isFluid) {
if (isFluid && NEIModContainer.isGTNHLibLoaded()) {
return NumberFormatUtil.formatNumberCompact(amount, FluidSlotAmountFormat.OPTIONS);
}
return amount < 10_000 ? String.valueOf(amount) : ReadableNumberConverter.INSTANCE.toWideReadableForm(amount);
}
public static String formatChance(float chance) { public static String formatChance(float chance) {
return CHANCE_FORMAT.format(chance); return CHANCE_FORMAT.format(chance);
} }
@@ -363,17 +363,7 @@ public class BookmarksGridSlot extends ItemsGridSlot {
final float panelFactor = (rect.w - 2) / (DEFAULT_SLOT_SIZE - 2); final float panelFactor = (rect.w - 2) / (DEFAULT_SLOT_SIZE - 2);
final long stackSize = this.bookmarkItem.getStackSize(amount); final long stackSize = this.bookmarkItem.getStackSize(amount);
int color = 0xFFFFFF; int color = 0xFFFFFF;
String amountString = ""; String amountString = NEIClientUtils.formatSlotAmount(stackSize, this.isFluidDisplay);
if (stackSize < 10_000) {
amountString = String.valueOf(stackSize);
} else {
amountString = ReadableNumberConverter.INSTANCE.toWideReadableForm(stackSize);
}
if (this.isFluidDisplay) {
amountString += "L";
}
if (this.bookmarkItem.chance != PositionedStack.CHANCE_FULL) { if (this.bookmarkItem.chance != PositionedStack.CHANCE_FULL) {
amountString = "~" + amountString; amountString = "~" + amountString;
@@ -29,7 +29,6 @@ import codechicken.nei.drawable.DrawableResource;
import codechicken.nei.guihook.GuiContainerManager; import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.recipe.Recipe.RecipeId; import codechicken.nei.recipe.Recipe.RecipeId;
import codechicken.nei.scroll.GuiHelper; import codechicken.nei.scroll.GuiHelper;
import codechicken.nei.util.ReadableNumberConverter;
class CraftingTreeCanvas { class CraftingTreeCanvas {
@@ -409,12 +408,7 @@ class CraftingTreeCanvas {
} }
protected void drawStackSize(ItemTreeSlot node, long stackSize, int x, int y, boolean resolved) { protected void drawStackSize(ItemTreeSlot node, long stackSize, int x, int y, boolean resolved) {
String amountString = stackSize < 10_000 ? String.valueOf(stackSize) String amountString = NEIClientUtils.formatSlotAmount(stackSize, node.isFluidDisplay);
: ReadableNumberConverter.INSTANCE.toWideReadableForm(stackSize);
if (node.isFluidDisplay) {
amountString += "L";
}
final boolean hasOutputChance = node.prefItem != null && node.prefItem.chance != PositionedStack.CHANCE_FULL; final boolean hasOutputChance = node.prefItem != null && node.prefItem.chance != PositionedStack.CHANCE_FULL;
int color = 0xFFFFFF; int color = 0xFFFFFF;
@@ -143,12 +143,7 @@ class StatsPanel extends ScrollContainer {
} }
private void drawStackSize() { private void drawStackSize() {
String amountString = stackSize < 10_000 ? String.valueOf(stackSize) final String amountString = NEIClientUtils.formatSlotAmount(stackSize, this.isFluidDisplay);
: ReadableNumberConverter.INSTANCE.toWideReadableForm(stackSize);
if (this.isFluidDisplay) {
amountString += "L";
}
NEIClientUtils.drawNEIOverlayText( NEIClientUtils.drawNEIOverlayText(
amountString, amountString,
@@ -9,8 +9,8 @@ import net.minecraftforge.fluids.FluidRegistry;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.item.FluidDrawer.FillDirection; import codechicken.nei.item.FluidDrawer.FillDirection;
import codechicken.nei.util.ReadableNumberConverter;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@@ -48,14 +48,7 @@ public class FluidDisplayRenderer implements IItemRenderer {
return; return;
} }
String amountString = ""; final String amountString = NEIClientUtils.formatSlotAmount(amount, true);
if (amount < 10_000) {
amountString = String.valueOf(amount) + "L";
} else {
amountString = ReadableNumberConverter.INSTANCE.toWideReadableForm(amount) + "L";
}
final FontRenderer fontRender = Minecraft.getMinecraft().fontRenderer; final FontRenderer fontRender = Minecraft.getMinecraft().fontRenderer;
float smallTextScale = fontRender.getUnicodeFlag() ? 3F / 4F : 1F / 2F; float smallTextScale = fontRender.getUnicodeFlag() ? 3F / 4F : 1F / 2F;
GL11.glPushAttrib(GL11.GL_ENABLE_BIT); GL11.glPushAttrib(GL11.GL_ENABLE_BIT);