Using a unified number converter to display short versions of numbers

This commit is contained in:
thatsIch
2015-03-29 15:21:24 +02:00
parent 9a7329598e
commit c9d67e40af
5 changed files with 346 additions and 135 deletions
@@ -60,12 +60,13 @@ import appeng.core.localization.PlayerMessages;
import appeng.helpers.Reflected;
import appeng.me.GridAccessException;
import appeng.util.Platform;
import appeng.util.ReadableNumberConverter;
import appeng.util.item.AEItemStack;
public class PartStorageMonitor extends PartMonitor implements IPartStorageMonitor, IStackWatcherHost
{
private static final ReadableNumberConverter NUMBER_CONVERTER = ReadableNumberConverter.INSTANCE;
IAEItemStack configuredItem;
boolean isLocked;
IStackWatcher myWatcher;
@@ -93,7 +94,7 @@ public class PartStorageMonitor extends PartMonitor implements IPartStorageMonit
data.setBoolean( "isLocked", this.isLocked );
NBTTagCompound myItem = new NBTTagCompound();
if ( this.configuredItem != null )
if( this.configuredItem != null )
this.configuredItem.writeToNBT( myItem );
data.setTag( "configuredItem", myItem );
@@ -113,24 +114,24 @@ public class PartStorageMonitor extends PartMonitor implements IPartStorageMonit
@Override
public boolean onPartActivate( EntityPlayer player, Vec3 pos )
{
if ( Platform.isClient() )
if( Platform.isClient() )
return true;
if ( !this.proxy.isActive() )
if( !this.proxy.isActive() )
return false;
if ( !Platform.hasPermissions( this.getLocation(), player ) )
if( !Platform.hasPermissions( this.getLocation(), player ) )
return false;
TileEntity te = this.tile;
ItemStack eq = player.getCurrentEquippedItem();
if ( Platform.isWrench( player, eq, te.xCoord, te.yCoord, te.zCoord ) )
if( Platform.isWrench( player, eq, te.xCoord, te.yCoord, te.zCoord ) )
{
this.isLocked = !this.isLocked;
player.addChatMessage( ( this.isLocked ? PlayerMessages.isNowLocked : PlayerMessages.isNowUnlocked ).get() );
this.getHost().markForUpdate();
}
else if ( !this.isLocked )
else if( !this.isLocked )
{
this.configuredItem = AEItemStack.create( eq );
this.configureWatchers();
@@ -150,7 +151,7 @@ public class PartStorageMonitor extends PartMonitor implements IPartStorageMonit
data.writeByte( this.spin );
data.writeBoolean( this.isLocked );
data.writeBoolean( this.configuredItem != null );
if ( this.configuredItem != null )
if( this.configuredItem != null )
this.configuredItem.writeToPacket( data );
}
@@ -162,7 +163,7 @@ public class PartStorageMonitor extends PartMonitor implements IPartStorageMonit
this.spin = data.readByte();
this.isLocked = data.readBoolean();
boolean val = data.readBoolean();
if ( val )
if( val )
this.configuredItem = AEItemStack.loadItemStackFromPacket( data );
else
this.configuredItem = null;
@@ -175,20 +176,20 @@ public class PartStorageMonitor extends PartMonitor implements IPartStorageMonit
// update the system...
public void configureWatchers()
{
if ( this.myWatcher != null )
if( this.myWatcher != null )
this.myWatcher.clear();
try
{
if ( this.configuredItem != null )
if( this.configuredItem != null )
{
if ( this.myWatcher != null )
if( this.myWatcher != null )
this.myWatcher.add( this.configuredItem );
this.updateReportingValue( this.proxy.getStorage().getItemInventory() );
}
}
catch ( GridAccessException e )
catch( GridAccessException e )
{
// >.>
}
@@ -201,10 +202,10 @@ public class PartStorageMonitor extends PartMonitor implements IPartStorageMonit
private void updateReportingValue( IMEMonitor<IAEItemStack> itemInventory )
{
if ( this.configuredItem != null )
if( this.configuredItem != null )
{
IAEItemStack result = itemInventory.getStorageList().findPrecise( this.configuredItem );
if ( result == null )
if( result == null )
this.configuredItem.setStackSize( 0 );
else
this.configuredItem.setStackSize( result.getStackSize() );
@@ -216,7 +217,7 @@ public class PartStorageMonitor extends PartMonitor implements IPartStorageMonit
protected void finalize() throws Throwable
{
super.finalize();
if ( this.dspList != null )
if( this.dspList != null )
GLAllocation.deleteDisplayLists( this.dspList );
}
@@ -224,23 +225,23 @@ public class PartStorageMonitor extends PartMonitor implements IPartStorageMonit
@SideOnly( Side.CLIENT )
public void renderDynamic( double x, double y, double z, IPartRenderHelper rh, RenderBlocks renderer )
{
if ( this.dspList == null )
if( this.dspList == null )
this.dspList = GLAllocation.generateDisplayLists( 1 );
Tessellator tess = Tessellator.instance;
if ( Platform.isDrawing( tess ) )
if( Platform.isDrawing( tess ) )
return;
if ( ( this.clientFlags & ( this.POWERED_FLAG | this.CHANNEL_FLAG ) ) != ( this.POWERED_FLAG | this.CHANNEL_FLAG ) )
if( ( this.clientFlags & ( this.POWERED_FLAG | this.CHANNEL_FLAG ) ) != ( this.POWERED_FLAG | this.CHANNEL_FLAG ) )
return;
IAEItemStack ais = (IAEItemStack) this.getDisplayed();
if ( ais != null )
if( ais != null )
{
GL11.glPushMatrix();
GL11.glTranslated( x + 0.5, y + 0.5, z + 0.5 );
if ( this.updateList )
if( this.updateList )
{
this.updateList = false;
GL11.glNewList( this.dspList, GL11.GL_COMPILE_AND_EXECUTE );
@@ -272,38 +273,38 @@ public class PartStorageMonitor extends PartMonitor implements IPartStorageMonit
ForgeDirection d = this.side;
GL11.glTranslated( d.offsetX * 0.77, d.offsetY * 0.77, d.offsetZ * 0.77 );
if ( d == ForgeDirection.UP )
if( d == ForgeDirection.UP )
{
GL11.glScalef( 1.0f, -1.0f, 1.0f );
GL11.glRotatef( 90.0f, 1.0f, 0.0f, 0.0f );
GL11.glRotatef( this.spin * 90.0F, 0, 0, 1 );
}
if ( d == ForgeDirection.DOWN )
if( d == ForgeDirection.DOWN )
{
GL11.glScalef( 1.0f, -1.0f, 1.0f );
GL11.glRotatef( -90.0f, 1.0f, 0.0f, 0.0f );
GL11.glRotatef( this.spin * -90.0F, 0, 0, 1 );
}
if ( d == ForgeDirection.EAST )
if( d == ForgeDirection.EAST )
{
GL11.glScalef( -1.0f, -1.0f, -1.0f );
GL11.glRotatef( -90.0f, 0.0f, 1.0f, 0.0f );
}
if ( d == ForgeDirection.WEST )
if( d == ForgeDirection.WEST )
{
GL11.glScalef( -1.0f, -1.0f, -1.0f );
GL11.glRotatef( 90.0f, 0.0f, 1.0f, 0.0f );
}
if ( d == ForgeDirection.NORTH )
if( d == ForgeDirection.NORTH )
{
GL11.glScalef( -1.0f, -1.0f, -1.0f );
}
if ( d == ForgeDirection.SOUTH )
if( d == ForgeDirection.SOUTH )
{
GL11.glScalef( -1.0f, -1.0f, -1.0f );
GL11.glRotatef( 180.0f, 0.0f, 1.0f, 0.0f );
@@ -329,7 +330,7 @@ public class PartStorageMonitor extends PartMonitor implements IPartStorageMonit
ClientHelper.proxy.doRenderItem( sis, this.tile.getWorldObj() );
}
catch ( Exception e )
catch( Exception e )
{
AELog.error( e );
}
@@ -339,22 +340,13 @@ public class PartStorageMonitor extends PartMonitor implements IPartStorageMonit
GL11.glTranslatef( 0.0f, 0.14f, -0.24f );
GL11.glScalef( 1.0f / 62.0f, 1.0f / 62.0f, 1.0f / 62.0f );
long qty = ais.getStackSize();
if ( qty > 999999999999L )
qty = 999999999999L;
String msg = Long.toString( qty );
if ( qty > 1000000000 )
msg = Long.toString( qty / 1000000000 ) + 'B';
else if ( qty > 1000000 )
msg = Long.toString( qty / 1000000 ) + 'M';
else if ( qty > 9999 )
msg = Long.toString( qty / 1000 ) + 'K';
final long stackSize = ais.getStackSize();
final String renderedStackSize = NUMBER_CONVERTER.toHumanReadableForm( stackSize );
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
int width = fr.getStringWidth( msg );
int width = fr.getStringWidth( renderedStackSize );
GL11.glTranslatef( -0.5f * width, 0.0f, -1.0f );
fr.drawString( msg, 0, 0, 0 );
fr.drawString( renderedStackSize, 0, 0, 0 );
GL11.glPopAttrib();
}
@@ -375,9 +367,9 @@ public class PartStorageMonitor extends PartMonitor implements IPartStorageMonit
@Override
public void onStackChange( IItemList o, IAEStack fullStack, IAEStack diffStack, BaseActionSource src, StorageChannel chan )
{
if ( this.configuredItem != null )
if( this.configuredItem != null )
{
if ( fullStack == null )
if( fullStack == null )
this.configuredItem.setStackSize( 0 );
else
this.configuredItem.setStackSize( fullStack.getStackSize() );