mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-07-17 17:32:55 +00:00

OK, so let's get this out of the way, there's some actual changes mixed in here too. I'm really sorry: - Turtles can now not be renamed with unnamed item tags (previously it would clear the name, this seemed a little unideal). - commands.getBlock(s)Data will also include NBT. Now, onto the horror story which is these inspection changes: - Make a lot of methods static - Typo fixes - Make utility classes final + private constructor - Lots of reformatting (ifs -> ternary, invert control flow, etc...) - ??? - Profit! I'm so going to regret this - can pretty much guarantee this is going to break something.
66 lines
1.7 KiB
Java
66 lines
1.7 KiB
Java
/*
|
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
|
* Send enquiries to dratcliffe@gmail.com
|
|
*/
|
|
|
|
package dan200.computercraft.shared.util;
|
|
|
|
public final class StringUtil
|
|
{
|
|
private StringUtil() {}
|
|
|
|
public static String normaliseLabel( String label )
|
|
{
|
|
if( label == null ) return null;
|
|
|
|
int length = Math.min( 32, label.length() );
|
|
StringBuilder builder = new StringBuilder( length );
|
|
for( int i = 0; i < length; i++ )
|
|
{
|
|
char c = label.charAt( i );
|
|
if( (c >= ' ' && c <= '~') || (c >= 161 && c <= 172) || (c >= 174 && c <= 255) )
|
|
{
|
|
builder.append( c );
|
|
}
|
|
else
|
|
{
|
|
builder.append( '?' );
|
|
}
|
|
}
|
|
|
|
return builder.toString();
|
|
}
|
|
|
|
/**
|
|
* Translates a Stat name
|
|
*/
|
|
@SuppressWarnings( "deprecation" )
|
|
public static String translate( String key )
|
|
{
|
|
return net.minecraft.util.text.translation.I18n.translateToLocal( key );
|
|
}
|
|
|
|
/**
|
|
* Translates a Stat name with format args
|
|
*/
|
|
@SuppressWarnings( "deprecation" )
|
|
public static String translateFormatted( String key, Object... format )
|
|
{
|
|
return net.minecraft.util.text.translation.I18n.translateToLocalFormatted( key, format );
|
|
}
|
|
|
|
public static byte[] encodeString( String string )
|
|
{
|
|
byte[] chars = new byte[string.length()];
|
|
|
|
for( int i = 0; i < chars.length; i++ )
|
|
{
|
|
char c = string.charAt( i );
|
|
chars[i] = c < 256 ? (byte) c : 63;
|
|
}
|
|
|
|
return chars;
|
|
}
|
|
}
|