initial commit
This commit is contained in:
parent
3c9ee26b06
commit
22186c33b9
1458 changed files with 282792 additions and 0 deletions
104
java/src/game/color/Colorizer.java
Executable file
104
java/src/game/color/Colorizer.java
Executable file
|
@ -0,0 +1,104 @@
|
|||
package game.color;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import game.FileUtils;
|
||||
import game.biome.Biome;
|
||||
import game.renderer.texture.TextureUtil;
|
||||
import game.world.BlockPos;
|
||||
import game.world.IWorldAccess;
|
||||
|
||||
public enum Colorizer {
|
||||
NONE(0xffffff), BASIC(0x37b500), PINE(0x3f993f), BIRCH(0x68a723);
|
||||
|
||||
private interface ColorResolver {
|
||||
int getColorAtPos(Biome biome, BlockPos pos);
|
||||
}
|
||||
|
||||
private static final ColorResolver GRASS_COLOR = new ColorResolver() {
|
||||
public int getColorAtPos(Biome biome, BlockPos pos) {
|
||||
return biome.getGrassColorAtPos(pos);
|
||||
}
|
||||
};
|
||||
private static final ColorResolver FOLIAGE_COLOR = new ColorResolver() {
|
||||
public int getColorAtPos(Biome biome, BlockPos pos) {
|
||||
return biome.getFoliageColorAtPos(pos);
|
||||
}
|
||||
};
|
||||
private static final ColorResolver WATER_COLOR_MULTIPLIER = new ColorResolver() {
|
||||
public int getColorAtPos(Biome biome, BlockPos pos) {
|
||||
return biome.waterColor;
|
||||
}
|
||||
};
|
||||
private static final String GRASS_TEX = "textures/world/grass.png";
|
||||
private static final String FOLIAGE_TEX = "textures/world/foliage.png";
|
||||
private static final int[] GRASS = new int[65536];
|
||||
private static final int[] FOLIAGE = new int[65536];
|
||||
|
||||
private final int color;
|
||||
|
||||
public static int getGrassColor(double temp, double rain) {
|
||||
rain = rain * temp;
|
||||
int i = (int)((1.0D - temp) * 255.0D);
|
||||
int j = (int)((1.0D - rain) * 255.0D);
|
||||
int k = j << 8 | i;
|
||||
return k > GRASS.length ? 0xFFFF00FF : GRASS[k];
|
||||
}
|
||||
|
||||
public static int getFoliageColor(double temp, double rain) {
|
||||
rain = rain * temp;
|
||||
int i = (int)((1.0D - temp) * 255.0D);
|
||||
int j = (int)((1.0D - rain) * 255.0D);
|
||||
return FOLIAGE[j << 8 | i];
|
||||
}
|
||||
|
||||
public static void reload() {
|
||||
BufferedImage img;
|
||||
try {
|
||||
img = TextureUtil.readImage(FileUtils.getResource(GRASS_TEX));
|
||||
img.getRGB(0, 0, 256, 256, GRASS, 0, 256);
|
||||
}
|
||||
catch(Exception e) {
|
||||
}
|
||||
try {
|
||||
img = TextureUtil.readImage(FileUtils.getResource(FOLIAGE_TEX));
|
||||
img.getRGB(0, 0, 256, 256, FOLIAGE, 0, 256);
|
||||
}
|
||||
catch(Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
private static int getColor(IWorldAccess access, BlockPos pos, ColorResolver resolver) {
|
||||
int r = 0;
|
||||
int g = 0;
|
||||
int b = 0;
|
||||
|
||||
for(BlockPos.MutableBlockPos loc : BlockPos.getAllInBoxMutable(pos.add(-1, 0, -1), pos.add(1, 0, 1))) {
|
||||
int c = resolver.getColorAtPos(access.getBiomeGenForCoords(loc), loc);
|
||||
r += (c & 16711680) >> 16;
|
||||
g += (c & 65280) >> 8;
|
||||
b += c & 255;
|
||||
}
|
||||
|
||||
return (r / 9 & 255) << 16 | (g / 9 & 255) << 8 | b / 9 & 255;
|
||||
}
|
||||
|
||||
public static int getGrassColor(IWorldAccess access, BlockPos pos) {
|
||||
return getColor(access, pos, GRASS_COLOR);
|
||||
}
|
||||
|
||||
public static int getFoliageColor(IWorldAccess access, BlockPos pos) {
|
||||
return getColor(access, pos, FOLIAGE_COLOR);
|
||||
}
|
||||
|
||||
public static int getWaterColor(IWorldAccess access, BlockPos pos) {
|
||||
return getColor(access, pos, WATER_COLOR_MULTIPLIER);
|
||||
}
|
||||
|
||||
private Colorizer(int color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return this.color;
|
||||
}
|
||||
}
|
146
java/src/game/color/DyeColor.java
Executable file
146
java/src/game/color/DyeColor.java
Executable file
|
@ -0,0 +1,146 @@
|
|||
package game.color;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import game.collect.Maps;
|
||||
import game.properties.IStringSerializable;
|
||||
|
||||
public enum DyeColor implements IStringSerializable
|
||||
{
|
||||
WHITE(0, 15, "white", "Weiß", "Weißes", "Weißer", "Weiße", "Knochenmehl", 16777215, TextColor.WHITE),
|
||||
ORANGE(1, 14, "orange", "Orange", "Oranges", "Oranger", "Orange", "Oranger Farbstoff", 14188339, TextColor.ORANGE),
|
||||
MAGENTA(2, 13, "magenta", "Magenta", "Magenta", "Magenta", "Magenta", "Magenta Farbstoff", 11685080, TextColor.NEON),
|
||||
LIGHT_BLUE(3, 12, "light_blue", "Hellblau", "Hellblaues", "Hellblauer", "Hellblaue", "Hellblauer Farbstoff", 6724056, TextColor.BLUE),
|
||||
YELLOW(4, 11, "yellow", "Gelb", "Gelbes", "Gelber", "Gelbe", "Gelber Farbstoff", 15066419, TextColor.YELLOW),
|
||||
LIME(5, 10, "lime", "Hellgrün", "Hellgrünes", "Hellgrüner", "Hellgrüne", "Hellgrüner Farbstoff", 8375321, TextColor.GREEN),
|
||||
PINK(6, 9, "pink", "Rosa", "Rosa", "Rosa", "Rosa", "Rosa Farbstoff", 15892389, TextColor.MAGENTA),
|
||||
GRAY(7, 8, "gray", "Grau", "Graues", "Grauer", "Graue", "Grauer Farbstoff", 5000268, TextColor.GRAY),
|
||||
SILVER(8, 7, "silver", "Hellgrau", "Hellgraues", "Hellgrauer", "Hellgraue", "Hellgrauer Farbstoff", 10066329, TextColor.LGRAY),
|
||||
CYAN(9, 6, "cyan", "Türkis", "Türkises", "Türkiser", "Türkise", "Türkiser Farbstoff", 5013401, TextColor.CYAN),
|
||||
PURPLE(10, 5, "purple", "Violett", "Violettes", "Violetter", "Violette", "Violetter Farbstoff", 8339378, TextColor.DMAGENTA),
|
||||
BLUE(11, 4, "blue", "Blau", "Blaues", "Blauer", "Blaue", "Lapislazuli", 3361970, TextColor.MIDNIGHT),
|
||||
BROWN(12, 3, "brown", "Braun", "Braunes", "Brauner", "Braune", "Kakaobohnen", 6704179, TextColor.ORANGE),
|
||||
GREEN(13, 2, "green", "Grün", "Grünes", "Grüner", "Grüne", "Kaktusgrün", 6717235, TextColor.DGREEN),
|
||||
RED(14, 1, "red", "Rot", "Rotes", "Roter", "Rote", "Roter Farbstoff", 10040115, TextColor.DRED),
|
||||
BLACK(15, 0, "black", "Schwarz", "Schwarzes", "Schwarzer", "Schwarze", "Tintenbeutel", 1644825, TextColor.BLACK);
|
||||
|
||||
private static final Map<String, DyeColor> LOOKUP = Maps.newHashMap();
|
||||
private static final DyeColor[] META_LOOKUP = new DyeColor[values().length];
|
||||
private static final DyeColor[] DYE_DMG_LOOKUP = new DyeColor[values().length];
|
||||
|
||||
private final int meta;
|
||||
private final int dyeDamage;
|
||||
private final String name;
|
||||
private final String display;
|
||||
private final String subject;
|
||||
private final String msubject;
|
||||
private final String fsubject;
|
||||
private final String dye;
|
||||
private final int color;
|
||||
private final TextColor chatColor;
|
||||
|
||||
private DyeColor(int meta, int dyeDamage, String name, String display, String subject, String msubject,
|
||||
String fsubject, String dye, int colorIn, TextColor chatColor)
|
||||
{
|
||||
this.meta = meta;
|
||||
this.dyeDamage = dyeDamage;
|
||||
this.name = name;
|
||||
this.display = display;
|
||||
this.subject = subject;
|
||||
this.msubject = msubject;
|
||||
this.fsubject = fsubject;
|
||||
this.dye = dye;
|
||||
this.color = colorIn;
|
||||
this.chatColor = chatColor;
|
||||
}
|
||||
|
||||
public int getMetadata()
|
||||
{
|
||||
return this.meta;
|
||||
}
|
||||
|
||||
public int getDyeDamage()
|
||||
{
|
||||
return this.dyeDamage;
|
||||
}
|
||||
|
||||
public int getColor()
|
||||
{
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public static DyeColor byDyeDamage(int damage)
|
||||
{
|
||||
if (damage < 0 || damage >= DYE_DMG_LOOKUP.length)
|
||||
{
|
||||
damage = 0;
|
||||
}
|
||||
|
||||
return DYE_DMG_LOOKUP[damage];
|
||||
}
|
||||
|
||||
public static DyeColor byMetadata(int meta)
|
||||
{
|
||||
if (meta < 0 || meta >= META_LOOKUP.length)
|
||||
{
|
||||
meta = 0;
|
||||
}
|
||||
|
||||
return META_LOOKUP[meta];
|
||||
}
|
||||
|
||||
public static DyeColor getByName(String name) {
|
||||
DyeColor type = LOOKUP.get(name.toLowerCase());
|
||||
return type == null ? WHITE : type;
|
||||
}
|
||||
|
||||
public static DyeColor getByString(String name) {
|
||||
DyeColor type = LOOKUP.get(name.toLowerCase());
|
||||
if(type != null)
|
||||
return type;
|
||||
int meta;
|
||||
try {
|
||||
meta = Integer.parseInt(name);
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
if(meta < 0 || meta >= META_LOOKUP.length)
|
||||
return null;
|
||||
return META_LOOKUP[meta];
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getDisplay()
|
||||
{
|
||||
return this.display;
|
||||
}
|
||||
|
||||
public String getSubject(Integer type)
|
||||
{
|
||||
return type == null ? this.display : (type < 0 ? this.fsubject : (type > 0 ? this.msubject : this.subject));
|
||||
}
|
||||
|
||||
public String getDye()
|
||||
{
|
||||
return this.dye;
|
||||
}
|
||||
|
||||
static {
|
||||
for (DyeColor color : values())
|
||||
{
|
||||
LOOKUP.put(color.name, color);
|
||||
META_LOOKUP[color.getMetadata()] = color;
|
||||
DYE_DMG_LOOKUP[color.getDyeDamage()] = color;
|
||||
}
|
||||
}
|
||||
}
|
85
java/src/game/color/TextColor.java
Executable file
85
java/src/game/color/TextColor.java
Executable file
|
@ -0,0 +1,85 @@
|
|||
package game.color;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public enum TextColor {
|
||||
NULL(0x00),
|
||||
RESET(0x01),
|
||||
BROWN(0x02, 0x8c5606),
|
||||
DBROWN(0x03, 0x56250b),
|
||||
DGREEN(0x04, 0x007f00),
|
||||
DRED(0x05, 0x7f0000),
|
||||
DMAGENTA(0x06, 0x6f006f),
|
||||
DVIOLET(0x07, 0x5400be),
|
||||
ORK(0x08, 0x487c00),
|
||||
ACID(0x09, 0x80ff00),
|
||||
NEWLINE(0x0a),
|
||||
COL1(0x0b, 0x000000),
|
||||
COL2(0x0c, 0x000000),
|
||||
COL3(0x0d, 0x000000),
|
||||
COL4(0x0e, 0x000000),
|
||||
COL5(0x0f, 0x000000),
|
||||
BLACK(0x10, 0x000000),
|
||||
DGRAY(0x11, 0x585858),
|
||||
GRAY(0x12, 0x808080),
|
||||
LGRAY(0x13, 0xc0c0c0),
|
||||
WHITE(0x14, 0xffffff),
|
||||
RED(0x15, 0xcf0000),
|
||||
GREEN(0x16, 0x00cf00),
|
||||
BLUE(0x17, 0x0000cf),
|
||||
YELLOW(0x18, 0xbfbf00),
|
||||
MAGENTA(0x19, 0xbf00bf),
|
||||
CYAN(0x1a, 0x00bfbf),
|
||||
VIOLET(0x1b, 0x6000ff),
|
||||
ORANGE(0x1c, 0xff7000),
|
||||
CRIMSON(0x1d, 0x601010),
|
||||
MIDNIGHT(0x1e, 0x000080),
|
||||
NEON(0x1f, 0x80c0f0),
|
||||
SPACE(0x20),
|
||||
UNKNOWN(0x7f),
|
||||
SGA_A(0x80),
|
||||
SGA_Z(0x99),
|
||||
BUG(0x9a),
|
||||
INVALID(0x9b),
|
||||
DEMON(0x9c),
|
||||
IMP(0x9d),
|
||||
HORNS(0x9e),
|
||||
BLKHEART(0x9f);
|
||||
|
||||
private static final Pattern STRIP_PATTERN = Pattern.compile("[\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000b\u000c\r\u000e\u000f"
|
||||
+ "\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f]");
|
||||
|
||||
private static final int[] COLORS = new int[32];
|
||||
|
||||
private final String format;
|
||||
public final char code;
|
||||
public final int color;
|
||||
|
||||
public static String stripCodes(String text) {
|
||||
return text == null ? null : STRIP_PATTERN.matcher(text).replaceAll("");
|
||||
}
|
||||
|
||||
public static int getColor(char code) {
|
||||
return code < COLORS.length ? COLORS[code] : 0x000000;
|
||||
}
|
||||
|
||||
private TextColor(int code) {
|
||||
this(code, 0x000000);
|
||||
}
|
||||
|
||||
private TextColor(int code, int color) {
|
||||
this.format = Character.toString(this.code = (char)code);
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.format;
|
||||
}
|
||||
|
||||
static {
|
||||
for(TextColor color : values()) {
|
||||
if(color.code < COLORS.length)
|
||||
COLORS[color.code] = color.color;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue