1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-26 00:46:54 +00:00

Simplify the palette payload to an int array

This commit is contained in:
Lignum 2017-05-05 18:47:43 +02:00
parent 39a56c8e55
commit 3de674dfb1
No known key found for this signature in database
GPG Key ID: 0889206F5A8A700D

View File

@ -53,26 +53,45 @@ public class Palette
}
}
private static int encodeRGB8( float[] rgb )
{
int r = (int)( rgb[0] * 255 ) & 0xFF;
int g = (int)( rgb[1] * 255 ) & 0xFF;
int b = (int)( rgb[2] * 255 ) & 0xFF;
return ( r << 16 ) | ( g << 8 ) | b;
}
private static float[] decodeRGB8( int rgb )
{
return new float[]
{
(( rgb >> 16 ) & 0xFF) / 255.0f,
(( rgb >> 8 ) & 0xFF) / 255.0f,
( rgb & 0xFF ) / 255.0f
};
}
public NBTTagCompound writeToNBT( NBTTagCompound nbt )
{
int[] rgb8 = new int[colours.length];
for(int i = 0; i < colours.length; ++i)
{
String prefix = "term_palette_colour_" + i;
nbt.setFloat( prefix + "_r", colours[i][0] );
nbt.setFloat( prefix + "_g", colours[i][1] );
nbt.setFloat( prefix + "_b", colours[i][2] );
rgb8[i] = encodeRGB8( colours[i] );
}
nbt.setIntArray( "term_palette", rgb8 );
return nbt;
}
public void readFromNBT( NBTTagCompound nbt )
{
int[] rgb8 = nbt.getIntArray( "term_palette" );
for(int i = 0; i < colours.length; ++i)
{
String prefix = "term_palette_colour_" + i;
colours[i][0] = nbt.getFloat( prefix + "_r" );
colours[i][1] = nbt.getFloat( prefix + "_g" );
colours[i][2] = nbt.getFloat( prefix + "_b" );
colours[i] = decodeRGB8( rgb8[i] );
}
}
}