mirror of
https://github.com/GTNewHorizons/CodeChickenCore.git
synced 2026-11-19 20:09:35 +00:00
Cleaned up directory layout
This commit is contained in:
1 parent
32fa471c44
commit
0a14b64e12
105 files changed
+1
-35
No files matched your search
@@ -0,0 +1,145 @@
|
||||
package codechicken.lib.colour;
|
||||
|
||||
import codechicken.lib.math.MathHelper;
|
||||
import codechicken.lib.util.Copyable;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public abstract class Colour implements Copyable<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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public Colour set(Colour colour)
|
||||
{
|
||||
r = colour.r;
|
||||
g = colour.g;
|
||||
b = colour.b;
|
||||
a = colour.a;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean equals(Colour colour)
|
||||
{
|
||||
return colour != null && rgba() == colour.rgba();
|
||||
}
|
||||
}
|
||||
@@ -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,49 @@
|
||||
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);
|
||||
}
|
||||
|
||||
public static int multiply(int c1, int c2) {
|
||||
if(c1 == -1) return c2;
|
||||
if(c2 == -1) return c1;
|
||||
int r = (((c1 >>> 24) * (c2 >>> 24)) & 0xFF00) << 16;
|
||||
int g = (((c1 >> 16 & 0xFF) * (c2 >> 16 & 0xFF)) & 0xFF00) << 8;
|
||||
int b = ((c1 >> 8 & 0xFF) * (c2 >> 8 & 0xFF)) & 0xFF00;
|
||||
int a = ((c1 & 0xFF) * (c2 & 0xFF)) >> 8;
|
||||
return r|g|b|a;
|
||||
}
|
||||
|
||||
public static int multiplyC(int c, float f) {
|
||||
int r = (int) ((c >>> 24) * f);
|
||||
int g = (int) ((c >> 16 & 0xFF) * f);
|
||||
int b = (int) ((c >> 8 & 0xFF) * f);
|
||||
return r<<24 | g<<16 | b<<8 | c&0xFF;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package codechicken.lib.colour;
|
||||
|
||||
import codechicken.lib.math.MathHelper;
|
||||
import codechicken.lib.render.TextureUtils;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
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