mirror of
https://github.com/GTNewHorizons/CodeChickenCore.git
synced 2026-11-22 13:19:39 +00:00
Initial Commit
This commit is contained in:
1 parent
397135f687
commit
0f32dd8620
82 files changed
+10693
No files matched your search
@@ -0,0 +1,139 @@
|
||||
package codechicken.lib.colour;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import codechicken.lib.math.MathHelper;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public abstract class Colour
|
||||
{
|
||||
public byte r;
|
||||
public byte g;
|
||||
public byte b;
|
||||
public byte a;
|
||||
|
||||
public Colour(int r, int g, int b, int a)
|
||||
{
|
||||
this.r = (byte) r;
|
||||
this.g = (byte) g;
|
||||
this.b = (byte) b;
|
||||
this.a = (byte) a;
|
||||
}
|
||||
|
||||
public Colour(Colour colour)
|
||||
{
|
||||
r = colour.r;
|
||||
g = colour.g;
|
||||
b = colour.b;
|
||||
a = colour.a;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void glColour()
|
||||
{
|
||||
GL11.glColor4ub(r, g, b, a);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void glColour(int a)
|
||||
{
|
||||
GL11.glColor4ub(r, g, b, (byte) a);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Deprecated
|
||||
public void glColour(byte a)
|
||||
{
|
||||
GL11.glColor4ub(r, g, b, a);
|
||||
}
|
||||
|
||||
public abstract int pack();
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return getClass().getSimpleName() + "[0x" + Integer.toHexString(pack()).toUpperCase() + "]";
|
||||
}
|
||||
|
||||
public Colour add(Colour colour2)
|
||||
{
|
||||
a += colour2.a;
|
||||
r += colour2.r;
|
||||
g += colour2.g;
|
||||
b += colour2.b;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Colour sub(Colour colour2)
|
||||
{
|
||||
int ia = (a & 0xFF) - (colour2.a & 0xFF);
|
||||
int ir = (r & 0xFF) - (colour2.r & 0xFF);
|
||||
int ig = (g & 0xFF) - (colour2.g & 0xFF);
|
||||
int ib = (b & 0xFF) - (colour2.b & 0xFF);
|
||||
a = (byte) (ia < 0 ? 0 : ia);
|
||||
r = (byte) (ir < 0 ? 0 : ir);
|
||||
g = (byte) (ig < 0 ? 0 : ig);
|
||||
b = (byte) (ib < 0 ? 0 : ib);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Colour invert()
|
||||
{
|
||||
a = (byte) (0xFF - (a & 0xFF));
|
||||
r = (byte) (0xFF - (r & 0xFF));
|
||||
g = (byte) (0xFF - (g & 0xFF));
|
||||
b = (byte) (0xFF - (b & 0xFF));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Colour multiply(Colour colour2)
|
||||
{
|
||||
a = (byte) ((a & 0xFF) * ((colour2.a & 0xFF) / 255D));
|
||||
r = (byte) ((r & 0xFF) * ((colour2.r & 0xFF) / 255D));
|
||||
g = (byte) ((g & 0xFF) * ((colour2.g & 0xFF) / 255D));
|
||||
b = (byte) ((b & 0xFF) * ((colour2.b & 0xFF) / 255D));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Colour scale(double d)
|
||||
{
|
||||
a = (byte) ((a & 0xFF) * d);
|
||||
r = (byte) ((r & 0xFF) * d);
|
||||
g = (byte) ((g & 0xFF) * d);
|
||||
b = (byte) ((b & 0xFF) * d);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Colour interpolate(Colour colour2, double d)
|
||||
{
|
||||
return this.add(colour2.copy().sub(this).scale(d));
|
||||
}
|
||||
|
||||
public Colour multiplyC(double d)
|
||||
{
|
||||
r = (byte) MathHelper.clip((r & 0xFF) * d, 0, 255);
|
||||
g = (byte) MathHelper.clip((g & 0xFF) * d, 0, 255);
|
||||
b = (byte) MathHelper.clip((b & 0xFF) * d, 0, 255);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public abstract Colour copy();
|
||||
|
||||
public int rgb()
|
||||
{
|
||||
return (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF);
|
||||
}
|
||||
|
||||
public int argb()
|
||||
{
|
||||
return (a & 0xFF) << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF);
|
||||
}
|
||||
|
||||
public int rgba()
|
||||
{
|
||||
return (r & 0xFF) << 24 | (g & 0xFF) << 16 | (b & 0xFF) << 8 | (a & 0xFF);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package codechicken.lib.colour;
|
||||
|
||||
public class ColourARGB extends Colour
|
||||
{
|
||||
public ColourARGB(int colour)
|
||||
{
|
||||
super((colour >> 16) & 0xFF, (colour >> 8) & 0xFF, colour & 0xFF, (colour >> 24) & 0xFF);
|
||||
}
|
||||
|
||||
public ColourARGB(int a, int r, int g, int b)
|
||||
{
|
||||
super(r, g, b, a);
|
||||
}
|
||||
|
||||
public ColourARGB(ColourARGB colour)
|
||||
{
|
||||
super(colour);
|
||||
}
|
||||
|
||||
public ColourARGB copy()
|
||||
{
|
||||
return new ColourARGB(this);
|
||||
}
|
||||
|
||||
public int pack()
|
||||
{
|
||||
return pack(this);
|
||||
}
|
||||
|
||||
public static int pack(Colour colour)
|
||||
{
|
||||
return (colour.a&0xFF) << 24 | (colour.r&0xFF) << 16 | (colour.g&0xFF) << 8 | (colour.b&0xFF);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package codechicken.lib.colour;
|
||||
|
||||
public class ColourRGBA extends Colour
|
||||
{
|
||||
public ColourRGBA(int colour)
|
||||
{
|
||||
super((colour >> 24) & 0xFF, (colour >> 16) & 0xFF, (colour >> 8) & 0xFF, colour & 0xFF);
|
||||
}
|
||||
|
||||
public ColourRGBA(double r, double g, double b, double a)
|
||||
{
|
||||
super((int) (255 * r), (int) (255 * g), (int) (255 * b), (int) (255 * a));
|
||||
}
|
||||
|
||||
public ColourRGBA(int r, int g, int b, int a)
|
||||
{
|
||||
super(r, g, b, a);
|
||||
}
|
||||
|
||||
public ColourRGBA(ColourRGBA colour)
|
||||
{
|
||||
super(colour);
|
||||
}
|
||||
|
||||
public int pack()
|
||||
{
|
||||
return pack(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Colour copy()
|
||||
{
|
||||
return new ColourRGBA(this);
|
||||
}
|
||||
|
||||
public static int pack(Colour colour)
|
||||
{
|
||||
return (colour.r&0xFF) << 24 | (colour.g&0xFF) << 16 | (colour.b&0xFF) << 8 | (colour.a&0xFF);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package codechicken.lib.colour;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import codechicken.lib.math.MathHelper;
|
||||
import codechicken.lib.render.TextureUtils;
|
||||
|
||||
public class CustomGradient
|
||||
{
|
||||
public int[] gradient;
|
||||
|
||||
public CustomGradient(ResourceLocation textureFile)
|
||||
{
|
||||
BufferedImage img = TextureUtils.loadBufferedImage(textureFile);
|
||||
int[] data = new int[img.getWidth()];
|
||||
img.getRGB(0, 0, img.getWidth(), 1, data, 0, img.getWidth());
|
||||
gradient = new int[img.getWidth()];
|
||||
for(int i = 0; i < data.length; i++)
|
||||
gradient[i] = (data[i]<<8)|(((data[i])>>24)&0xFF);
|
||||
}
|
||||
|
||||
public ColourRGBA getColour(double position)
|
||||
{
|
||||
return new ColourRGBA(getColourI(position));
|
||||
}
|
||||
|
||||
public int getColourI(double position)
|
||||
{
|
||||
int off = (int)MathHelper.clip(gradient.length*position, 0, gradient.length-1);
|
||||
return gradient[off];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user