Move quantity formatter to API, fixes #1608
This commit is contained in:
@@ -15,6 +15,7 @@ import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReaderWriterHan
|
||||
import com.raoulvdberge.refinedstorage.api.solderer.ISoldererRegistry;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDiskBehavior;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IQuantityFormatter;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -36,9 +37,16 @@ public interface IRSAPI {
|
||||
@Nonnull
|
||||
IComparer getComparer();
|
||||
|
||||
/**
|
||||
* @return the quantity formatter
|
||||
*/
|
||||
@Nonnull
|
||||
IQuantityFormatter getQuantityFormatter();
|
||||
|
||||
/**
|
||||
* @return the network node factory
|
||||
*/
|
||||
@Nonnull
|
||||
INetworkNodeRegistry getNetworkNodeRegistry();
|
||||
|
||||
/**
|
||||
@@ -54,6 +62,7 @@ public interface IRSAPI {
|
||||
/**
|
||||
* @return the default storage disk behavior
|
||||
*/
|
||||
@Nonnull
|
||||
IStorageDiskBehavior getDefaultStorageDiskBehavior();
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.raoulvdberge.refinedstorage.api.util;
|
||||
|
||||
/**
|
||||
* Utilities for formatting quantities.
|
||||
*/
|
||||
public interface IQuantityFormatter {
|
||||
/**
|
||||
* Formats a quantity as they are formatted in the Grid.
|
||||
* Formatted as following: "####0.#".
|
||||
* <p>
|
||||
* If the quantity is equal to or bigger than 1000 it will be displayed as the quantity divided by 1000 (without any decimals) and a "K" appended.
|
||||
* If the quantity is equal to or bigger than 1000000 it will be displayed as the quantity divided by 1000000 (without any decimals) and a "M" appended.
|
||||
*
|
||||
* @param qty the quantity
|
||||
* @return the formatted quantity
|
||||
*/
|
||||
String formatWithUnits(int qty);
|
||||
|
||||
/**
|
||||
* Formats a quantity as they are formatted on the disk tooltips.
|
||||
* Formatted as following: "#,###".
|
||||
*
|
||||
* @param qty the quantity
|
||||
* @return the formatted quantity
|
||||
*/
|
||||
String format(int qty);
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReaderWriterHan
|
||||
import com.raoulvdberge.refinedstorage.api.solderer.ISoldererRegistry;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDiskBehavior;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IQuantityFormatter;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementList;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementRegistry;
|
||||
@@ -33,6 +34,7 @@ import com.raoulvdberge.refinedstorage.apiimpl.network.readerwriter.ReaderWriter
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.solderer.SoldererRegistry;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskBehavior;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.util.Comparer;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.util.QuantityFormatter;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.util.StackListFluid;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.util.StackListItem;
|
||||
import com.raoulvdberge.refinedstorage.capability.CapabilityNetworkNodeProxy;
|
||||
@@ -58,6 +60,7 @@ public class API implements IRSAPI {
|
||||
private static final IRSAPI INSTANCE = new API();
|
||||
|
||||
private IComparer comparer = new Comparer();
|
||||
private IQuantityFormatter quantityFormatter = new QuantityFormatter();
|
||||
private INetworkNodeRegistry networkNodeRegistry = new NetworkNodeRegistry();
|
||||
private IStorageDiskBehavior storageDiskBehavior = new StorageDiskBehavior();
|
||||
private ISoldererRegistry soldererRegistry = new SoldererRegistry();
|
||||
@@ -97,6 +100,13 @@ public class API implements IRSAPI {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public IQuantityFormatter getQuantityFormatter() {
|
||||
return quantityFormatter;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public INetworkNodeRegistry getNetworkNodeRegistry() {
|
||||
return networkNodeRegistry;
|
||||
}
|
||||
@@ -122,6 +132,7 @@ public class API implements IRSAPI {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public IStorageDiskBehavior getDefaultStorageDiskBehavior() {
|
||||
return storageDiskBehavior;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class CraftingMonitorElementFluidRender implements ICraftingMonitorElemen
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scale(scale, scale, 1);
|
||||
|
||||
drawers.getStringDrawer().draw(RenderUtils.getOffsetOnScale(x + 21 + offset, scale), RenderUtils.getOffsetOnScale(y + 7, scale), RenderUtils.QUANTITY_FORMATTER.format((float) stack.amount / 1000F) + "x " + stack.getLocalizedName());
|
||||
drawers.getStringDrawer().draw(RenderUtils.getOffsetOnScale(x + 21 + offset, scale), RenderUtils.getOffsetOnScale(y + 7, scale), API.instance().getQuantityFormatter().format(stack.amount) + " mB " + stack.getLocalizedName());
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReader;
|
||||
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReaderWriterChannel;
|
||||
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReaderWriterHandler;
|
||||
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IWriter;
|
||||
import com.raoulvdberge.refinedstorage.util.RenderUtils;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
@@ -102,7 +102,7 @@ public class ReaderWriterHandlerFluids implements IReaderWriterHandler {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return Collections.singletonList(new TextComponentString(RenderUtils.QUANTITY_FORMATTER.format((float) stack.amount / 1000F) + "x ").appendSibling(new TextComponentTranslation(stack.getUnlocalizedName())));
|
||||
return Collections.singletonList(new TextComponentString(API.instance().getQuantityFormatter().format(stack.amount) + " mB ").appendSibling(new TextComponentTranslation(stack.getUnlocalizedName())));
|
||||
}
|
||||
|
||||
private class FluidTankReaderWriter implements IFluidTank, IFluidHandler {
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.util;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.util.IQuantityFormatter;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.Locale;
|
||||
|
||||
public class QuantityFormatter implements IQuantityFormatter {
|
||||
private DecimalFormat formatterWithUnits = new DecimalFormat("####0.#", DecimalFormatSymbols.getInstance(Locale.US));
|
||||
private DecimalFormat formatter = new DecimalFormat("#,###", DecimalFormatSymbols.getInstance(Locale.US));
|
||||
|
||||
public QuantityFormatter() {
|
||||
formatterWithUnits.setRoundingMode(RoundingMode.DOWN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatWithUnits(int qty) {
|
||||
if (qty >= 1_000_000) {
|
||||
float qtyShort = (float) qty / 1_000_000F;
|
||||
|
||||
if (qty >= 100_000_000) {
|
||||
qtyShort = Math.round(qtyShort); // XXX.XM looks weird.
|
||||
}
|
||||
|
||||
return formatterWithUnits.format(qtyShort) + "M";
|
||||
} else if (qty >= 1000) {
|
||||
float qtyShort = (float) qty / 1000F;
|
||||
|
||||
if (qty >= 100_000) {
|
||||
qtyShort = Math.round(qtyShort); // XXX.XK looks weird.
|
||||
}
|
||||
|
||||
return formatterWithUnits.format(qtyShort) + "K";
|
||||
}
|
||||
|
||||
return String.valueOf(qty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format(int qty) {
|
||||
return formatter.format(qty);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.raoulvdberge.refinedstorage.gui;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.IGuiStorage;
|
||||
import com.raoulvdberge.refinedstorage.container.ContainerBase;
|
||||
import com.raoulvdberge.refinedstorage.gui.sidebutton.*;
|
||||
import com.raoulvdberge.refinedstorage.util.RenderUtils;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
@@ -85,8 +85,8 @@ public class GuiStorage extends GuiBase {
|
||||
public void drawForeground(int mouseX, int mouseY) {
|
||||
drawString(7, 7, t(gui.getGuiTitle()));
|
||||
drawString(7, 42, gui.getCapacity() == -1 ?
|
||||
t("misc.refinedstorage:storage.stored_minimal", RenderUtils.formatQuantity(gui.getStored())) :
|
||||
t("misc.refinedstorage:storage.stored_capacity_minimal", RenderUtils.formatQuantity(gui.getStored()), RenderUtils.formatQuantity(gui.getCapacity()))
|
||||
t("misc.refinedstorage:storage.stored_minimal", API.instance().getQuantityFormatter().formatWithUnits(gui.getStored())) :
|
||||
t("misc.refinedstorage:storage.stored_capacity_minimal", API.instance().getQuantityFormatter().formatWithUnits(gui.getStored()), API.instance().getQuantityFormatter().formatWithUnits(gui.getCapacity()))
|
||||
);
|
||||
|
||||
if (texture.contains("disk_drive")) { // HACK!
|
||||
@@ -103,8 +103,8 @@ public class GuiStorage extends GuiBase {
|
||||
}
|
||||
|
||||
drawTooltip(mouseX, mouseY, (gui.getCapacity() == -1 ?
|
||||
t("misc.refinedstorage:storage.stored_minimal", RenderUtils.QUANTITY_FORMATTER_UNFORMATTED.format(gui.getStored())) :
|
||||
t("misc.refinedstorage:storage.stored_capacity_minimal", RenderUtils.QUANTITY_FORMATTER_UNFORMATTED.format(gui.getStored()), RenderUtils.QUANTITY_FORMATTER_UNFORMATTED.format(gui.getCapacity()))
|
||||
t("misc.refinedstorage:storage.stored_minimal", API.instance().getQuantityFormatter().format(gui.getStored())) :
|
||||
t("misc.refinedstorage:storage.stored_capacity_minimal", API.instance().getQuantityFormatter().format(gui.getStored()), API.instance().getQuantityFormatter().format(gui.getCapacity()))
|
||||
) + "\n" + TextFormatting.GRAY + t("misc.refinedstorage:storage.full", full));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.raoulvdberge.refinedstorage.gui.grid.stack;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageTracker;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.gui.GuiBase;
|
||||
import com.raoulvdberge.refinedstorage.util.RenderUtils;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
@@ -56,14 +56,14 @@ public class GridStackFluid implements IGridStack {
|
||||
|
||||
@Override
|
||||
public String getFormattedFullQuantity() {
|
||||
return RenderUtils.QUANTITY_FORMATTER_UNFORMATTED.format(getQuantity()) + " mB";
|
||||
return API.instance().getQuantityFormatter().format(getQuantity()) + " mB";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(GuiBase gui, int x, int y) {
|
||||
GuiBase.FLUID_RENDERER.draw(gui.mc, x, y, stack);
|
||||
|
||||
gui.drawQuantity(x, y, RenderUtils.formatQuantity((int) ((float) stack.amount / 1000F)));
|
||||
gui.drawQuantity(x, y, API.instance().getQuantityFormatter().formatWithUnits((int) ((float) stack.amount / 1000F)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.raoulvdberge.refinedstorage.gui.grid.stack;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageTracker;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageTrackerEntry;
|
||||
import com.raoulvdberge.refinedstorage.gui.GuiBase;
|
||||
import com.raoulvdberge.refinedstorage.util.RenderUtils;
|
||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -119,7 +119,7 @@ public class GridStackItem implements IGridStack {
|
||||
|
||||
@Override
|
||||
public String getFormattedFullQuantity() {
|
||||
return RenderUtils.QUANTITY_FORMATTER_UNFORMATTED.format(getQuantity());
|
||||
return API.instance().getQuantityFormatter().format(getQuantity());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -129,7 +129,7 @@ public class GridStackItem implements IGridStack {
|
||||
if (displayCraftText) {
|
||||
text = I18n.format("gui.refinedstorage:grid.craft");
|
||||
} else if (stack.getCount() > 1) {
|
||||
text = RenderUtils.formatQuantity(stack.getCount());
|
||||
text = API.instance().getQuantityFormatter().formatWithUnits(getQuantity());
|
||||
}
|
||||
|
||||
gui.drawItem(x, y, stack, true, text);
|
||||
|
||||
@@ -2,10 +2,10 @@ package com.raoulvdberge.refinedstorage.item;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RSBlocks;
|
||||
import com.raoulvdberge.refinedstorage.RSItems;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeFluidStorage;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskFluid;
|
||||
import com.raoulvdberge.refinedstorage.block.FluidStorageType;
|
||||
import com.raoulvdberge.refinedstorage.util.RenderUtils;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -36,9 +36,9 @@ public class ItemBlockFluidStorage extends ItemBlockBase {
|
||||
NBTTagCompound tag = stack.getTagCompound().getCompoundTag(NetworkNodeFluidStorage.NBT_STORAGE);
|
||||
|
||||
if (type == FluidStorageType.TYPE_CREATIVE) {
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored", RenderUtils.QUANTITY_FORMATTER_UNFORMATTED.format(StorageDiskFluid.getStored(tag))));
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored", API.instance().getQuantityFormatter().format(StorageDiskFluid.getStored(tag))));
|
||||
} else {
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", RenderUtils.QUANTITY_FORMATTER_UNFORMATTED.format(StorageDiskFluid.getStored(tag)), RenderUtils.QUANTITY_FORMATTER_UNFORMATTED.format(type.getCapacity())));
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", API.instance().getQuantityFormatter().format(StorageDiskFluid.getStored(tag)), API.instance().getQuantityFormatter().format(type.getCapacity())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ package com.raoulvdberge.refinedstorage.item;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RSBlocks;
|
||||
import com.raoulvdberge.refinedstorage.RSItems;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeStorage;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskItem;
|
||||
import com.raoulvdberge.refinedstorage.block.ItemStorageType;
|
||||
import com.raoulvdberge.refinedstorage.util.RenderUtils;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -36,9 +36,9 @@ public class ItemBlockStorage extends ItemBlockBase {
|
||||
NBTTagCompound tag = stack.getTagCompound().getCompoundTag(NetworkNodeStorage.NBT_STORAGE);
|
||||
|
||||
if (type == ItemStorageType.TYPE_CREATIVE) {
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored", RenderUtils.QUANTITY_FORMATTER_UNFORMATTED.format(StorageDiskItem.getStored(tag))));
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored", API.instance().getQuantityFormatter().format(StorageDiskItem.getStored(tag))));
|
||||
} else {
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", RenderUtils.QUANTITY_FORMATTER_UNFORMATTED.format(StorageDiskItem.getStored(tag)), RenderUtils.QUANTITY_FORMATTER_UNFORMATTED.format(type.getCapacity())));
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", API.instance().getQuantityFormatter().format(StorageDiskItem.getStored(tag)), API.instance().getQuantityFormatter().format(type.getCapacity())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import com.raoulvdberge.refinedstorage.api.storage.StorageDiskType;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskFluid;
|
||||
import com.raoulvdberge.refinedstorage.block.FluidStorageType;
|
||||
import com.raoulvdberge.refinedstorage.util.RenderUtils;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
@@ -110,9 +109,9 @@ public class ItemFluidStorageDisk extends ItemBase implements IStorageDiskProvid
|
||||
|
||||
if (storage.isValid(stack)) {
|
||||
if (storage.getCapacity() == -1) {
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored", RenderUtils.QUANTITY_FORMATTER_UNFORMATTED.format(storage.getStored())));
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored", API.instance().getQuantityFormatter().format(storage.getStored())));
|
||||
} else {
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", RenderUtils.QUANTITY_FORMATTER_UNFORMATTED.format(storage.getStored()), RenderUtils.QUANTITY_FORMATTER_UNFORMATTED.format(storage.getCapacity())));
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", API.instance().getQuantityFormatter().format(storage.getStored()), API.instance().getQuantityFormatter().format(storage.getCapacity())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import com.raoulvdberge.refinedstorage.api.storage.StorageDiskType;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskItem;
|
||||
import com.raoulvdberge.refinedstorage.block.ItemStorageType;
|
||||
import com.raoulvdberge.refinedstorage.util.RenderUtils;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
@@ -102,9 +101,9 @@ public class ItemStorageDisk extends ItemBase implements IStorageDiskProvider<It
|
||||
|
||||
if (storage.isValid(stack)) {
|
||||
if (storage.getCapacity() == -1) {
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored", RenderUtils.QUANTITY_FORMATTER_UNFORMATTED.format(storage.getStored())));
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored", API.instance().getQuantityFormatter().format(storage.getStored())));
|
||||
} else {
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", RenderUtils.QUANTITY_FORMATTER_UNFORMATTED.format(storage.getStored()), RenderUtils.QUANTITY_FORMATTER_UNFORMATTED.format(storage.getCapacity())));
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", API.instance().getQuantityFormatter().format(storage.getStored()), API.instance().getQuantityFormatter().format(storage.getCapacity())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.raoulvdberge.refinedstorage.render;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.tile.TileStorageMonitor;
|
||||
import com.raoulvdberge.refinedstorage.tile.config.IType;
|
||||
import com.raoulvdberge.refinedstorage.util.RenderUtils;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
@@ -27,7 +27,7 @@ public class TileEntitySpecialRendererStorageMonitor extends TileEntitySpecialRe
|
||||
float rotY = 0;
|
||||
float rotZ = 0;
|
||||
|
||||
String amount = tile.getType() == IType.ITEMS ? RenderUtils.formatQuantity(tile.getAmount()) : RenderUtils.QUANTITY_FORMATTER.format((float) tile.getAmount() / 1000F);
|
||||
String amount = tile.getType() == IType.ITEMS ? API.instance().getQuantityFormatter().formatWithUnits(tile.getAmount()) : API.instance().getQuantityFormatter().formatWithUnits((int) ((float) tile.getAmount() / 1000F));
|
||||
|
||||
// Very bad, but I don't know how to translate a 2D font width to a 3D font width...
|
||||
float textWidth = 0;
|
||||
|
||||
@@ -22,16 +22,9 @@ import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import javax.vecmath.Matrix4f;
|
||||
import javax.vecmath.Vector3f;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
|
||||
public final class RenderUtils {
|
||||
public static final DecimalFormat QUANTITY_FORMATTER = new DecimalFormat("####0.#", DecimalFormatSymbols.getInstance(Locale.US));
|
||||
public static final DecimalFormat QUANTITY_FORMATTER_UNFORMATTED = new DecimalFormat("#,###", DecimalFormatSymbols.getInstance(Locale.US));
|
||||
|
||||
public static final Matrix4f EMPTY_MATRIX_TRANSFORM = getTransform(0, 0, 0, 0, 0, 0, 1.0f).getMatrix();
|
||||
|
||||
// From ForgeBlockStateV1
|
||||
@@ -40,32 +33,6 @@ public final class RenderUtils {
|
||||
private static ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> DEFAULT_ITEM_TRANSFORM;
|
||||
private static ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> DEFAULT_BLOCK_TRANSFORM;
|
||||
|
||||
static {
|
||||
QUANTITY_FORMATTER.setRoundingMode(RoundingMode.DOWN);
|
||||
}
|
||||
|
||||
public static String formatQuantity(int qty) {
|
||||
if (qty >= 1_000_000) {
|
||||
float qtyShort = (float) qty / 1_000_000F;
|
||||
|
||||
if (qty >= 100_000_000) {
|
||||
qtyShort = Math.round(qtyShort); // XXX.XM looks weird.
|
||||
}
|
||||
|
||||
return QUANTITY_FORMATTER.format(qtyShort) + "M";
|
||||
} else if (qty >= 1000) {
|
||||
float qtyShort = (float) qty / 1000F;
|
||||
|
||||
if (qty >= 100_000) {
|
||||
qtyShort = Math.round(qtyShort); // XXX.XK looks weird.
|
||||
}
|
||||
|
||||
return QUANTITY_FORMATTER.format(qtyShort) + "K";
|
||||
}
|
||||
|
||||
return String.valueOf(qty);
|
||||
}
|
||||
|
||||
public static AxisAlignedBB getBounds(int fromX, int fromY, int fromZ, int toX, int toY, int toZ) {
|
||||
return new AxisAlignedBB((float) fromX / 16F, (float) fromY / 16F, (float) fromZ / 16F, (float) toX / 16F, (float) toY / 16F, (float) toZ / 16F);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user