Better quantity formatter, fixes #490
This commit is contained in:
@@ -32,6 +32,9 @@ import net.minecraftforge.items.wrapper.InvWrapper;
|
||||
import net.minecraftforge.items.wrapper.SidedInvWrapper;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -42,6 +45,12 @@ public final class RSUtils {
|
||||
private static final String NBT_SLOT = "Slot";
|
||||
private static final String NBT_ACCESS_TYPE = "AccessType";
|
||||
|
||||
public static final DecimalFormat QUANTITY_FORMATTER = new DecimalFormat("####0.#", DecimalFormatSymbols.getInstance(Locale.US));
|
||||
|
||||
static {
|
||||
QUANTITY_FORMATTER.setRoundingMode(RoundingMode.DOWN);
|
||||
}
|
||||
|
||||
public static void writeItemStack(ByteBuf buf, INetworkMaster network, ItemStack stack) {
|
||||
buf.writeInt(Item.getIdFromItem(stack.getItem()));
|
||||
buf.writeInt(stack.stackSize);
|
||||
@@ -261,10 +270,6 @@ public final class RSUtils {
|
||||
return stack.getFluid() == FluidRegistry.WATER || stack.getFluid() == FluidRegistry.LAVA || FluidRegistry.getBucketFluids().contains(stack.getFluid());
|
||||
}
|
||||
|
||||
public static String formatFluidStackQuantity(FluidStack stack) {
|
||||
return String.format(Locale.US, "%.1f", (float) stack.amount / 1000).replace(".0", "");
|
||||
}
|
||||
|
||||
public static FluidStack copyStackWithSize(FluidStack stack, int size) {
|
||||
FluidStack copy = stack.copy();
|
||||
copy.amount = size;
|
||||
|
@@ -33,7 +33,7 @@ public class CraftingMonitorElementFluidRender implements ICraftingMonitorElemen
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scale(scale, scale, 1);
|
||||
|
||||
drawers.getStringDrawer().draw(GuiBase.calculateOffsetOnScale(x + 21 + offset, scale), GuiBase.calculateOffsetOnScale(y + 7, scale), RSUtils.formatFluidStackQuantity(stack) + " " + stack.getLocalizedName());
|
||||
drawers.getStringDrawer().draw(GuiBase.calculateOffsetOnScale(x + 21 + offset, scale), GuiBase.calculateOffsetOnScale(y + 7, scale), RSUtils.QUANTITY_FORMATTER.format((float) stack.amount / 1000F) + " " + stack.getLocalizedName());
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
@@ -47,7 +47,7 @@ public class ClientStackFluid implements IClientStack {
|
||||
public void draw(GuiBase gui, int x, int y, boolean isOverWithShift) {
|
||||
GuiBase.FLUID_RENDERER.draw(gui.mc, x, y, stack);
|
||||
|
||||
gui.drawQuantity(x, y, RSUtils.formatFluidStackQuantity(stack));
|
||||
gui.drawQuantity(x, y, RSUtils.QUANTITY_FORMATTER.format((float) stack.amount / 1000F));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.raoulvdberge.refinedstorage.gui.grid.stack;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||
import com.raoulvdberge.refinedstorage.gui.GuiBase;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import joptsimple.internal.Strings;
|
||||
@@ -11,7 +12,6 @@ import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class ClientStackItem implements IClientStack {
|
||||
private int hash;
|
||||
@@ -77,9 +77,9 @@ public class ClientStackItem implements IClientStack {
|
||||
}
|
||||
|
||||
if (qty >= 1000000) {
|
||||
return String.format(Locale.US, "%.1f", (float) qty / 1000000).replace(".0", "") + "M";
|
||||
return RSUtils.QUANTITY_FORMATTER.format((float) qty / 1000000F) + "M";
|
||||
} else if (qty >= 1000) {
|
||||
return String.format(Locale.US, "%.1f", (float) qty / 1000).replace(".0", "") + "K";
|
||||
return RSUtils.QUANTITY_FORMATTER.format((float) qty / 1000F) + "K";
|
||||
} else if (qty == 1) {
|
||||
return null;
|
||||
} else if (qty == 0) {
|
||||
|
Reference in New Issue
Block a user