mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-12 19:20:29 +00:00
Merge pull request #288 from Wojbie/getPaletteColour-fix
Fix to getPalletteColour
This commit is contained in:
commit
54d202cf6b
@ -33,7 +33,7 @@ public class FixedWidthFontRenderer
|
||||
m_textureManager = textureManager;
|
||||
}
|
||||
|
||||
private static void greyscaleify( float[] rgb )
|
||||
private static void greyscaleify( double[] rgb )
|
||||
{
|
||||
Arrays.fill( rgb, ( rgb[0] + rgb[1] + rgb[2] ) / 3.0f );
|
||||
}
|
||||
@ -43,14 +43,14 @@ public class FixedWidthFontRenderer
|
||||
int column = index % 16;
|
||||
int row = index / 16;
|
||||
|
||||
float[] colour = p.getColour( 15 - color );
|
||||
double[] colour = p.getColour( 15 - color );
|
||||
if(greyscale)
|
||||
{
|
||||
greyscaleify( colour );
|
||||
}
|
||||
float r = colour[0];
|
||||
float g = colour[1];
|
||||
float b = colour[2];
|
||||
float r = (float)colour[0];
|
||||
float g = (float)colour[1];
|
||||
float b = (float)colour[2];
|
||||
|
||||
renderer.pos( x, y, 0.0 ).tex( (double) (column * FONT_WIDTH) / 256.0, (double) (row * FONT_HEIGHT ) / 256.0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
renderer.pos( x, y + FONT_HEIGHT, 0.0 ).tex( (double) (column * FONT_WIDTH) / 256.0, (double) ((row + 1) * FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
@ -62,14 +62,14 @@ public class FixedWidthFontRenderer
|
||||
|
||||
private void drawQuad( VertexBuffer renderer, double x, double y, int color, double width, Palette p, boolean greyscale )
|
||||
{
|
||||
float[] colour = p.getColour( 15 - color );
|
||||
double[] colour = p.getColour( 15 - color );
|
||||
if(greyscale)
|
||||
{
|
||||
greyscaleify( colour );
|
||||
}
|
||||
float r = colour[0];
|
||||
float g = colour[1];
|
||||
float b = colour[2];
|
||||
float r = (float)colour[0];
|
||||
float g = (float)colour[1];
|
||||
float b = (float)colour[2];
|
||||
|
||||
renderer.pos( x, y, 0.0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
renderer.pos( x, y + FONT_HEIGHT, 0.0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
|
@ -110,7 +110,7 @@ public class TermAPI implements ILuaAPI
|
||||
};
|
||||
}
|
||||
|
||||
public static void setColour( Terminal terminal, int colour, float r, float g, float b )
|
||||
public static void setColour( Terminal terminal, int colour, double r, double g, double b )
|
||||
{
|
||||
if( terminal.getPalette() != null )
|
||||
{
|
||||
@ -296,7 +296,7 @@ public class TermAPI implements ILuaAPI
|
||||
{
|
||||
int colour = 15 - parseColour( args );
|
||||
int hex = ((Double)args[1]).intValue();
|
||||
float[] rgb = Palette.decodeRGB8( hex );
|
||||
double[] rgb = Palette.decodeRGB8( hex );
|
||||
setColour( m_terminal, colour, rgb[0], rgb[1], rgb[2] );
|
||||
return null;
|
||||
}
|
||||
@ -304,9 +304,9 @@ public class TermAPI implements ILuaAPI
|
||||
if(args.length >= 4 && args[0] instanceof Double && args[1] instanceof Double && args[2] instanceof Double && args[3] instanceof Double)
|
||||
{
|
||||
int colour = 15 - parseColour( args );
|
||||
float r = ((Double)args[1]).floatValue();
|
||||
float g = ((Double)args[2]).floatValue();
|
||||
float b = ((Double)args[3]).floatValue();
|
||||
double r = (Double)args[1];
|
||||
double g = (Double)args[2];
|
||||
double b = (Double)args[3];
|
||||
setColour( m_terminal, colour, r, g, b );
|
||||
return null;
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ public class MonitorPeripheral implements IPeripheral
|
||||
{
|
||||
int colour = 15 - dan200.computercraft.core.apis.TermAPI.parseColour( args );
|
||||
int hex = ((Double)args[1]).intValue();
|
||||
float[] rgb = Palette.decodeRGB8( hex );
|
||||
double[] rgb = Palette.decodeRGB8( hex );
|
||||
dan200.computercraft.core.apis.TermAPI.setColour( terminal, colour, rgb[0], rgb[1], rgb[2] );
|
||||
return null;
|
||||
}
|
||||
@ -248,9 +248,9 @@ public class MonitorPeripheral implements IPeripheral
|
||||
if (args.length >= 4 && args[0] instanceof Double && args[1] instanceof Double && args[2] instanceof Double && args[3] instanceof Double)
|
||||
{
|
||||
int colour = 15 - dan200.computercraft.core.apis.TermAPI.parseColour( args );
|
||||
float r = ((Double)args[1]).floatValue();
|
||||
float g = ((Double)args[2]).floatValue();
|
||||
float b = ((Double)args[3]).floatValue();
|
||||
double r = (Double)args[1];
|
||||
double g = (Double)args[2];
|
||||
double b = (Double)args[3];
|
||||
dan200.computercraft.core.apis.TermAPI.setColour( terminal, colour, r, g, b );
|
||||
return null;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
public class Palette
|
||||
{
|
||||
private static final int PALETTE_SIZE = 16;
|
||||
private final float[][] colours = new float[PALETTE_SIZE][3];
|
||||
private final double[][] colours = new double[PALETTE_SIZE][3];
|
||||
|
||||
public static final Palette DEFAULT = new Palette();
|
||||
|
||||
@ -15,7 +15,7 @@ public class Palette
|
||||
resetColours();
|
||||
}
|
||||
|
||||
public void setColour(int i, float r, float g, float b)
|
||||
public void setColour(int i, double r, double g, double b)
|
||||
{
|
||||
if( i >= 0 && i < colours.length )
|
||||
{
|
||||
@ -30,7 +30,7 @@ public class Palette
|
||||
setColour( i, colour.getR(), colour.getG(), colour.getB() );
|
||||
}
|
||||
|
||||
public float[] getColour( int i )
|
||||
public double[] getColour( int i )
|
||||
{
|
||||
if( i >= 0 && i < colours.length )
|
||||
{
|
||||
@ -55,7 +55,7 @@ public class Palette
|
||||
}
|
||||
}
|
||||
|
||||
public static int encodeRGB8( float[] rgb )
|
||||
public static int encodeRGB8( double[] rgb )
|
||||
{
|
||||
int r = (int)( rgb[0] * 255 ) & 0xFF;
|
||||
int g = (int)( rgb[1] * 255 ) & 0xFF;
|
||||
@ -64,9 +64,9 @@ public class Palette
|
||||
return ( r << 16 ) | ( g << 8 ) | b;
|
||||
}
|
||||
|
||||
public static float[] decodeRGB8( int rgb )
|
||||
public static double[] decodeRGB8( int rgb )
|
||||
{
|
||||
return new float[]
|
||||
return new double[]
|
||||
{
|
||||
(( rgb >> 16 ) & 0xFF) / 255.0f,
|
||||
(( rgb >> 8 ) & 0xFF) / 255.0f,
|
||||
|
Loading…
Reference in New Issue
Block a user