Compare commits

..
Author SHA1 Message Date
Connor Colenso addb2f92e1 Stop craftable fluids drawing their amount twice
The craftables panel drew the stack with its amount, so NEI's fluid item
drew the amount and drawStackSize drew it again on top. Draw fluids
without their amount, as bookmarks already do.
2026-11-26 23:48:17 +00:00
Connor Colenso b784769426 Show fluid amounts over slots in compact form, without the L
Fluid amounts drawn over slots drop their L, since 1 L is 1 mB, a unit
doesn't fit in a slot and it ignored the L/mB setting anyway. With GTNHLib
loaded they use its compact formatting, so they follow the player's number
settings: exact up to 9,999, then 12.3K, 1.5M, rounded down. Without it
they keep the old short form. Covers the fluid display item, bookmarks,
craftables, the crafting tree and item rows in tooltips. Item counts are
unchanged.
2026-11-26 23:47:50 +00:00
20 changed files with 77 additions and 152 deletions

No files matched your search

@@ -192,10 +192,9 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
builder = BookmarkItem.builder(groupId, itemStack, recipe, BookmarkItemType.RESULT).multiplier(1); builder = BookmarkItem.builder(groupId, itemStack, recipe, BookmarkItemType.RESULT).multiplier(1);
} else if (recipeId != null) { } else if (recipeId != null) {
builder = BookmarkItem.builder(groupId, itemStack).recipeId(recipeId) builder = BookmarkItem.builder(groupId, itemStack).recipeId(recipeId)
.factor(StackInfo.getAmountLong(itemStack)).multiplier(1); .factor(StackInfo.getAmount(itemStack)).multiplier(1);
} else { } else {
builder = BookmarkItem.builder(groupId, itemStack).factor(1) builder = BookmarkItem.builder(groupId, itemStack).factor(1).multiplier(StackInfo.getAmount(itemStack));
.multiplier(StackInfo.getAmountLong(itemStack));
} }
if (existsRecipe) { if (existsRecipe) {
@@ -262,7 +261,7 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
builder = BookmarkItem.builder(groupId, stack, recipe, BookmarkItemType.RESULT); builder = BookmarkItem.builder(groupId, stack, recipe, BookmarkItemType.RESULT);
} else { } else {
builder = BookmarkItem.builder(groupId, stack).recipeId(recipeId) builder = BookmarkItem.builder(groupId, stack).recipeId(recipeId)
.factor(StackInfo.getAmountLong(stack)); .factor(StackInfo.getAmount(stack));
} }
this.grid.addItem(builder.multiplier(1).type(BookmarkItemType.ITEM).build(), true); this.grid.addItem(builder.multiplier(1).type(BookmarkItemType.ITEM).build(), true);
@@ -554,7 +553,7 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
} }
protected ItemStack getDraggedStackWithQuantity(ItemStack itemStack) { protected ItemStack getDraggedStackWithQuantity(ItemStack itemStack) {
return ItemQuantityField.prepareStackWithQuantity(itemStack, StackInfo.getAmountLong(itemStack)); return ItemQuantityField.prepareStackWithQuantity(itemStack, StackInfo.getAmount(itemStack));
} }
@Override @Override
@@ -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.getAmount(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,
@@ -215,7 +212,7 @@ public class ItemCraftablesPanel
@Override @Override
protected ItemStack getDraggedStackWithQuantity(ItemStack itemStack) { protected ItemStack getDraggedStackWithQuantity(ItemStack itemStack) {
return ItemQuantityField.prepareStackWithQuantity(itemStack, StackInfo.getAmountLong(itemStack)); return ItemQuantityField.prepareStackWithQuantity(itemStack, StackInfo.getAmount(itemStack));
} }
@Override @Override
@@ -389,11 +386,11 @@ public class ItemCraftablesPanel
} }
final ItemStack stack = Recipe.getMainResult(results, pStack -> pStack.items[0]).item; final ItemStack stack = Recipe.getMainResult(results, pStack -> pStack.items[0]).item;
long stackSize = 0; int stackSize = 0;
for (PositionedStack result : results) { for (PositionedStack result : results) {
if (containsSameType(result, stack)) { if (containsSameType(result, stack)) {
stackSize += StackInfo.getAmountLong(result.item); stackSize += StackInfo.getAmount(result.item);
} }
} }
@@ -34,7 +34,7 @@ public class ItemStackAmount {
} }
public void add(ItemStack item) { public void add(ItemStack item) {
add(item, StackInfo.getAmountLong(item)); add(item, (long) StackInfo.getAmount(item));
} }
public void add(ItemStack stack, Long value) { public void add(ItemStack stack, Long value) {
@@ -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);
} }
@@ -312,8 +331,7 @@ public class NEIClientUtils extends NEIServerUtils {
if (StackInfo.isFluidDisplayItem(stack.item)) { if (StackInfo.isFluidDisplayItem(stack.item)) {
final FluidStack requiredFluid = StackInfo.getFluid(stack.item); final FluidStack requiredFluid = StackInfo.getFluid(stack.item);
found = requiredFluid != null found = requiredFluid != null && consumeFluid(invStacks, remainingFluid, requiredFluid);
&& consumeFluid(invStacks, remainingFluid, requiredFluid, StackInfo.getAmountLong(stack.item));
} else { } else {
found = false; found = false;
@@ -333,8 +351,8 @@ public class NEIClientUtils extends NEIServerUtils {
} }
private static boolean consumeFluid(List<ItemStack> invStacks, Map<ItemStack, Long> remainingFluid, private static boolean consumeFluid(List<ItemStack> invStacks, Map<ItemStack, Long> remainingFluid,
FluidStack requiredFluid, long requiredAmount) { FluidStack requiredFluid) {
long need = requiredAmount; long need = requiredFluid.amount;
final List<ItemStack> matched = new ArrayList<>(); final List<ItemStack> matched = new ArrayList<>();
for (ItemStack is : invStacks) { for (ItemStack is : invStacks) {
@@ -365,7 +383,7 @@ public class NEIClientUtils extends NEIServerUtils {
return false; return false;
} }
long remainingNeed = requiredAmount; long remainingNeed = requiredFluid.amount;
for (ItemStack is : matched) { for (ItemStack is : matched) {
final long available = remainingFluid.get(is); final long available = remainingFluid.get(is);
final long consumed = Math.min(available, remainingNeed); final long consumed = Math.min(available, remainingNeed);
@@ -238,7 +238,6 @@ public class PositionedStack implements Cloneable {
/** The tank size the fill level is measured against, in mB. 0 means "always render full". */ /** The tank size the fill level is measured against, in mB. 0 means "always render full". */
protected int capacity = 0; protected int capacity = 0;
protected boolean flowingTexture = false; protected boolean flowingTexture = false;
protected boolean amountTooltip = true;
protected FillDirection fillDirection = FillDirection.AUTO; protected FillDirection fillDirection = FillDirection.AUTO;
private ItemStack cachedFluidItem; private ItemStack cachedFluidItem;
@@ -277,15 +276,6 @@ public class PositionedStack implements Cloneable {
return this; return this;
} }
public boolean hasAmountTooltip() {
return this.amountTooltip;
}
public Tank setAmountTooltip(boolean amountTooltip) {
this.amountTooltip = amountTooltip;
return this;
}
public FillDirection getFillDirection() { public FillDirection getFillDirection() {
return this.fillDirection; return this.fillDirection;
} }
@@ -311,11 +301,10 @@ public class PositionedStack implements Cloneable {
final List<String> customTooltip = super.getTooltip(); final List<String> customTooltip = super.getTooltip();
final FluidStack fluidStack = getFluidStack(); final FluidStack fluidStack = getFluidStack();
if (fluidStack != null && this.amountTooltip) { if (fluidStack != null && this.capacity > 0) {
tooltip.add( tooltip.add(
EnumChatFormatting.GRAY + NEIClientUtils.translate( EnumChatFormatting.GRAY + NEIClientUtils
"recipe.fluid.tank.amount", .translate("recipe.fluid.tank.amount", NEIClientUtils.formatFluid(fluidStack.amount)));
NEIClientUtils.formatFluid(StackInfo.getAmountLong(this.item))));
} }
if (customTooltip != null) { if (customTooltip != null) {
@@ -729,7 +729,7 @@ public abstract class ShortcutInputHandler {
for (ItemStack stack : playerInventory) { for (ItemStack stack : playerInventory) {
if (NEIClientUtils.areStacksSameTypeCraftingWithNBT(stack, item.itemStack)) { if (NEIClientUtils.areStacksSameTypeCraftingWithNBT(stack, item.itemStack)) {
amount += StackInfo.getAmountLong(stack); amount += StackInfo.getAmount(stack);
} }
} }
@@ -194,8 +194,7 @@ public class BookmarkGridGenerator {
|| group.crafting.calculatedItems.get(shadowIndex).calculatedType == CalculatedType.INGREDIENT; || group.crafting.calculatedItems.get(shadowIndex).calculatedType == CalculatedType.INGREDIENT;
final BookmarkItem shadowBookmarkItem = BookmarkItem.builder(bookmarkItem.groupId, bookmarkItem.itemStack) final BookmarkItem shadowBookmarkItem = BookmarkItem.builder(bookmarkItem.groupId, bookmarkItem.itemStack)
.multiplier(1).factor(StackInfo.getAmountLong(bookmarkItem.itemStack)) .multiplier(1).factor(StackInfo.getAmount(bookmarkItem.itemStack)).recipeId(bookmarkItem.recipeId)
.recipeId(bookmarkItem.recipeId)
.type(isIngredient ? BookmarkItemType.INGREDIENT : BookmarkItemType.RESULT) .type(isIngredient ? BookmarkItemType.INGREDIENT : BookmarkItemType.RESULT)
.permutations(Collections.emptyMap()).build(); .permutations(Collections.emptyMap()).build();
@@ -42,7 +42,7 @@ public class BookmarkItem {
this.groupId = groupId; this.groupId = groupId;
this.stack = stack; this.stack = stack;
this.factor = StackInfo.isFluidDisplayItem(stack) ? Math.max(nbTag.getLong("Count"), 1) : 1; this.factor = StackInfo.isFluidDisplayItem(stack) ? Math.max(nbTag.getInteger("Count"), 1) : 1;
} }
public Builder factor(long factor) { public Builder factor(long factor) {
@@ -105,7 +105,7 @@ public class BookmarkItem {
if (this.multiplier >= 0) { if (this.multiplier >= 0) {
multiplier = this.multiplier; multiplier = this.multiplier;
} else if (this.factor > 0) { } else if (this.factor > 0) {
multiplier = StackInfo.getAmountLong(this.stack) / this.factor; multiplier = StackInfo.getAmount(this.stack) / this.factor;
} }
return new BookmarkItem( return new BookmarkItem(
@@ -234,7 +234,7 @@ public class BookmarkItem {
for (RecipeIngredient res : items) { for (RecipeIngredient res : items) {
for (ItemStack perm : res.getPermutations()) { for (ItemStack perm : res.getPermutations()) {
if (NEIClientUtils.areStacksSameTypeWithNBT(emptyStack, StackInfo.withAmount(perm, 0))) { if (NEIClientUtils.areStacksSameTypeWithNBT(emptyStack, StackInfo.withAmount(perm, 0))) {
amount += 1L * StackInfo.getAmountLong(perm) * res.getChance(); amount += 1L * StackInfo.getAmount(perm) * res.getChance();
break; break;
} }
} }
@@ -271,15 +271,15 @@ public class BookmarkItem {
} }
if (jsonObject.has("multiplier")) { if (jsonObject.has("multiplier")) {
builder.multiplier(jsonObject.get("multiplier").getAsLong()); builder.multiplier(jsonObject.get("multiplier").getAsInt());
} }
if (jsonObject.has("factor")) { if (jsonObject.has("factor")) {
builder.factor(jsonObject.get("factor").getAsLong()); builder.factor(jsonObject.get("factor").getAsInt());
} }
if (jsonObject.has("chance")) { if (jsonObject.has("chance")) {
builder.chance(jsonObject.get("chance").getAsLong()); builder.chance(jsonObject.get("chance").getAsInt());
} }
if (jsonObject.get("recipeId") instanceof JsonObject recipeJson) { if (jsonObject.get("recipeId") instanceof JsonObject recipeJson) {
@@ -320,9 +320,8 @@ public class BookmarkItem {
final ItemStack newPerm = findPermutation(stack); final ItemStack newPerm = findPermutation(stack);
if (oldPerm != null && newPerm != null) { if (oldPerm != null && newPerm != null) {
final long oldAmount = StackInfo.getAmountLong(oldPerm); final long oldAmount = StackInfo.getAmount(oldPerm);
final long amount = oldAmount > 0 final long amount = oldAmount > 0 ? this.factor * this.chance * StackInfo.getAmount(newPerm) / oldAmount
? this.factor * this.chance * StackInfo.getAmountLong(newPerm) / oldAmount
: 0; : 0;
final long factor = (amount % PositionedStack.CHANCE_FULL) == 0 ? amount / PositionedStack.CHANCE_FULL final long factor = (amount % PositionedStack.CHANCE_FULL) == 0 ? amount / PositionedStack.CHANCE_FULL
: 1; : 1;
@@ -370,9 +369,8 @@ public class BookmarkItem {
final ItemStack newPerm = findPermutation(perm); final ItemStack newPerm = findPermutation(perm);
if (oldPerm != null && newPerm != null) { if (oldPerm != null && newPerm != null) {
final long oldAmount = StackInfo.getAmountLong(oldPerm); final long oldAmount = StackInfo.getAmount(oldPerm);
final long amount = oldAmount > 0 final long amount = oldAmount > 0 ? this.factor * this.chance * StackInfo.getAmount(newPerm) / oldAmount
? this.factor * this.chance * StackInfo.getAmountLong(newPerm) / oldAmount
: 0; : 0;
final long factor = (amount % PositionedStack.CHANCE_FULL) == 0 ? amount / PositionedStack.CHANCE_FULL final long factor = (amount % PositionedStack.CHANCE_FULL) == 0 ? amount / PositionedStack.CHANCE_FULL
: 1; : 1;
@@ -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,
@@ -51,7 +51,6 @@ import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils; import codechicken.nei.NEIClientUtils;
import codechicken.nei.NEIModContainer; import codechicken.nei.NEIModContainer;
import codechicken.nei.recipe.StackInfo; import codechicken.nei.recipe.StackInfo;
import codechicken.nei.recipe.stackinfo.GTFluidStackStringifyHandler;
import codechicken.nei.util.ItemUntranslator; import codechicken.nei.util.ItemUntranslator;
import codechicken.nei.util.ReadableNumberConverter; import codechicken.nei.util.ReadableNumberConverter;
import codechicken.nei.util.RenderTooltipEventHelper; import codechicken.nei.util.RenderTooltipEventHelper;
@@ -230,9 +229,7 @@ public class GuiContainerManager {
public static String itemCountDetails(ItemStack stack) { public static String itemCountDetails(ItemStack stack) {
final FluidStack fluid = StackInfo.getFluid(stack); final FluidStack fluid = StackInfo.getFluid(stack);
if (fluid != null) { if (fluid != null) {
// The fluid of a display item is limited to an int, its stored amount is not return fluidAmountDetails(fluid.amount * Math.max(1, stack.stackSize));
final long amount = StackInfo.isFluidDisplayItem(stack) ? StackInfo.getAmountLong(stack) : fluid.amount;
return fluidAmountDetails(amount * Math.max(1, stack.stackSize));
} else { } else {
return countDetails( return countDetails(
stack.stackSize, stack.stackSize,
@@ -246,35 +243,17 @@ public class GuiContainerManager {
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Nullable @Nullable
public static String fluidAmountDetails(FluidStack fluid) { public static String fluidAmountDetails(FluidStack fluid) {
return fluidAmountDetails(GTFluidStackStringifyHandler.getFluidAmount(fluid)); return fluidAmountDetails(fluid.amount);
} }
@Nullable @Nullable
public static String fluidAmountDetails(int amount) { public static String fluidAmountDetails(int amount) {
return fluidAmountDetails((long) amount); return countDetails(
} amount,
144,
@Nullable translate("inventory.tooltip.count.fluid", "%s = %s * %s + %s"),
public static String fluidAmountDetails(long amount) {
if (amount <= 144) return null;
final long remainder = amount % 144;
final String units = NEIClientUtils.formatNumber(amount / 144);
if (remainder > 0) {
return String.format(
translate("inventory.tooltip.count.fluid", "%s = %s * %s + %s"),
NEIClientUtils.formatFluid(amount),
units,
NEIClientUtils.formatFluid(144),
NEIClientUtils.formatFluid(remainder));
}
return String.format(
translate("inventory.tooltip.count.fluid", "%s = %s * %s"), translate("inventory.tooltip.count.fluid", "%s = %s * %s"),
NEIClientUtils.formatFluid(amount), NEIClientUtils::formatFluid);
units,
NEIClientUtils.formatFluid(144));
} }
/** /**
@@ -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);
@@ -17,7 +17,6 @@ import net.minecraftforge.fluids.IFluidContainerItem;
import codechicken.nei.NEIClientConfig; import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils; import codechicken.nei.NEIClientUtils;
import codechicken.nei.recipe.stackinfo.GTFluidStackStringifyHandler;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@@ -47,8 +46,7 @@ public class ItemFluidDisplay extends Item implements IFluidContainerItem {
} }
public static ItemStack createStack(FluidStack fluidStack) { public static ItemStack createStack(FluidStack fluidStack) {
return fluidStack == null ? null return fluidStack == null ? null : createStack(fluidStack.getFluid(), fluidStack.amount);
: createStack(fluidStack.getFluid(), GTFluidStackStringifyHandler.getFluidAmount(fluidStack));
} }
public static ItemStack createStack(Fluid fluid, long amount) { public static ItemStack createStack(Fluid fluid, long amount) {
@@ -487,11 +487,11 @@ public class Recipe {
stack = getMainResult(getResults(), RecipeIngredient::getItemStack).getItemStack(); stack = getMainResult(getResults(), RecipeIngredient::getItemStack).getItemStack();
} }
long stackSize = 0; int stackSize = 0;
for (RecipeIngredient result : this.results) { for (RecipeIngredient result : this.results) {
if (result.contains(stack)) { if (result.contains(stack)) {
stackSize += StackInfo.getAmountLong(result.getItemStack()); stackSize += result.getAmount();
} }
} }
@@ -121,13 +121,9 @@ public class StackInfo {
} }
public static int getAmount(ItemStack stack) { public static int getAmount(ItemStack stack) {
return (int) Math.min(getAmountLong(stack), Integer.MAX_VALUE);
}
public static long getAmountLong(ItemStack stack) {
if (stack == null) return 0; if (stack == null) return 0;
final NBTTagCompound nbTag = StackInfo.itemStackToNBT(stack); final NBTTagCompound nbTag = StackInfo.itemStackToNBT(stack);
return nbTag != null ? nbTag.getLong("Count") : 0; return nbTag != null ? nbTag.getInteger("Count") : 0;
} }
public static boolean equalItemAndNBT(ItemStack stackA, ItemStack stackB, boolean useNBT) { public static boolean equalItemAndNBT(ItemStack stackA, ItemStack stackB, boolean useNBT) {
@@ -155,7 +155,7 @@ public class RecipeChainTooltipLineHandler extends CompositeTooltipLineHandler {
for (ItemStack stack : items) { for (ItemStack stack : items) {
if (stack != null if (stack != null
&& NEIClientUtils.areStacksSameTypeCraftingWithNBT(stack, item.itemStack)) { && NEIClientUtils.areStacksSameTypeCraftingWithNBT(stack, item.itemStack)) {
amount += StackInfo.getAmountLong(stack); amount += StackInfo.getAmount(stack);
} }
} }
@@ -22,7 +22,6 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
protected static Class<?> itemFluidDisplay = null; protected static Class<?> itemFluidDisplay = null;
protected static Method getFluidFromDisplayStack = null; protected static Method getFluidFromDisplayStack = null;
private static Method getGTFluidAmount = null;
protected static Class<?> gtMetaGeneratedTool = null; protected static Class<?> gtMetaGeneratedTool = null;
protected static Field playSound = null; protected static Field playSound = null;
@@ -43,12 +42,6 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
"gregtech.common.items.GT_FluidDisplayItem"); "gregtech.common.items.GT_FluidDisplayItem");
getFluidFromDisplayStack = gtUtility.getMethod("getFluidFromDisplayStack", ItemStack.class); getFluidFromDisplayStack = gtUtility.getMethod("getFluidFromDisplayStack", ItemStack.class);
try {
getGTFluidAmount = gtUtility.getMethod("getFluidAmount", FluidStack.class);
} catch (NoSuchMethodException ignored) {
/* GregTech without long fluid stacks */
}
gtMetaGeneratedTool = ReflectionHelper.getClass( gtMetaGeneratedTool = ReflectionHelper.getClass(
loader, loader,
"gregtech.api.items.MetaGeneratedTool", "gregtech.api.items.MetaGeneratedTool",
@@ -59,18 +52,6 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
} }
} }
/** GregTech fluid stacks can hold more than {@link FluidStack#amount} does */
public static long getFluidAmount(FluidStack fluidStack) {
if (getGTFluidAmount != null) {
try {
return (long) getGTFluidAmount.invoke(null, fluidStack);
} catch (Exception ignored) {}
}
return fluidStack.amount;
}
@Override @Override
public NBTTagCompound convertItemStackToNBT(ItemStack stack, boolean saveStackSize) { public NBTTagCompound convertItemStackToNBT(ItemStack stack, boolean saveStackSize) {
@@ -80,7 +61,7 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
if (fluidStack != null) { if (fluidStack != null) {
final NBTTagCompound nbTag = new NBTTagCompound(); final NBTTagCompound nbTag = new NBTTagCompound();
nbTag.setString(FluidDisplayStackStringifyHandler.NBT_FLUID_NAME, fluidStack.getFluid().getName()); nbTag.setString(FluidDisplayStackStringifyHandler.NBT_FLUID_NAME, fluidStack.getFluid().getName());
nbTag.setLong("Count", saveStackSize ? getFluidAmount(fluidStack) : 144); nbTag.setInteger("Count", saveStackSize ? fluidStack.amount : 144);
return nbTag; return nbTag;
} }
} }
@@ -387,7 +387,7 @@ public class RecipeGroup {
protected boolean isSameStack(ItemStack stackA, ItemStack stackB) { protected boolean isSameStack(ItemStack stackA, ItemStack stackB) {
return stackA == stackB || NEIServerUtils.areStacksSameType(stackA, stackB) return stackA == stackB || NEIServerUtils.areStacksSameType(stackA, stackB)
&& StackInfo.getAmountLong(stackA) == StackInfo.getAmountLong(stackB); && StackInfo.getAmount(stackA) == StackInfo.getAmount(stackB);
} }
protected List<ItemStack> getFilteredPermutations(int member, Point slotKey) { protected List<ItemStack> getFilteredPermutations(int member, Point slotKey) {