Added helpers for hex and color output. (#3027)

This commit is contained in:
yueh
2017-08-12 14:52:31 +02:00
committed by GitHub
parent 3e2bc0e038
commit cdd76b7b22
2 changed files with 90 additions and 6 deletions
@@ -21,6 +21,8 @@ package appeng.util.helpers;
import com.google.common.base.Preconditions;
import net.minecraft.util.text.TextFormatting;
import appeng.api.util.AEColor;
@@ -57,4 +59,32 @@ public class P2PHelper
return (short) ( t & 0xFFFF );
}
public String toHexDigit( AEColor color )
{
return String.format( "%01X", color.ordinal() );
}
public String toHexString( short frequency )
{
return String.format( "%04X", frequency );
}
public String toColorHexDigit( AEColor color )
{
return TextFormatting.fromColorIndex( color.ordinal() ) + this.toHexDigit( color );
}
public String toColorHexString( short frequency )
{
final AEColor[] colors = toColors( frequency );
final StringBuilder builder = new StringBuilder();
for( AEColor aeColor : colors )
{
builder.append( this.toColorHexDigit( aeColor ) );
}
return builder.toString();
}
}