-
Notifications
You must be signed in to change notification settings - Fork 497
/
EnumColor.java
207 lines (184 loc) · 3.88 KB
/
EnumColor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/**
* Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* The BuildCraft API is distributed under the terms of the MIT License.
* Please check the contents of the license, which should be located
* as "LICENSE.API" in the BuildCraft source code distribution.
*/
package buildcraft.api.core;
import java.util.Locale;
import java.util.Random;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
import net.minecraft.util.StatCollector;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public enum EnumColor {
BLACK,
RED,
GREEN,
BROWN,
BLUE,
PURPLE,
CYAN,
LIGHT_GRAY,
GRAY,
PINK,
LIME,
YELLOW,
LIGHT_BLUE,
MAGENTA,
ORANGE,
WHITE;
public static final EnumColor[] VALUES = values();
public static final String[] DYES = {
"dyeBlack",
"dyeRed",
"dyeGreen",
"dyeBrown",
"dyeBlue",
"dyePurple",
"dyeCyan",
"dyeLightGray",
"dyeGray",
"dyePink",
"dyeLime",
"dyeYellow",
"dyeLightBlue",
"dyeMagenta",
"dyeOrange",
"dyeWhite"};
public static final String[] NAMES = {
"Black",
"Red",
"Green",
"Brown",
"Blue",
"Purple",
"Cyan",
"LightGray",
"Gray",
"Pink",
"Lime",
"Yellow",
"LightBlue",
"Magenta",
"Orange",
"White"};
public static final int[] DARK_HEX = {
0x2D2D2D,
0xA33835,
0x394C1E,
0x5C3A24,
0x3441A2,
0x843FBF,
0x36809E,
0x888888,
0x444444,
0xE585A0,
0x3FAA36,
0xCFC231,
0x7F9AD1,
0xFF64FF,
0xFF6A00,
0xFFFFFF};
public static final int[] LIGHT_HEX = {
0x181414,
0xBE2B27,
0x007F0E,
0x89502D,
0x253193,
0x7e34bf,
0x299799,
0xa0a7a7,
0x7A7A7A,
0xD97199,
0x39D52E,
0xFFD91C,
0x66AAFF,
0xD943C6,
0xEA7835,
0xe4e4e4};
@SideOnly(Side.CLIENT)
private static IIcon[] brushIcons;
public int getDarkHex() {
return DARK_HEX[ordinal()];
}
public int getLightHex() {
return LIGHT_HEX[ordinal()];
}
public static EnumColor fromId(int id) {
if (id < 0 || id >= VALUES.length) {
return WHITE;
}
return VALUES[id];
}
public static EnumColor fromDye(String dyeTag) {
for (int id = 0; id < DYES.length; id++) {
if (DYES[id].equals(dyeTag)) {
return VALUES[id];
}
}
return null;
}
public static EnumColor fromName(String name) {
for (int id = 0; id < NAMES.length; id++) {
if (NAMES[id].equals(name)) {
return VALUES[id];
}
}
return null;
}
public static EnumColor getRand() {
return VALUES[new Random().nextInt(VALUES.length)];
}
public EnumColor getNext() {
EnumColor next = VALUES[(ordinal() + 1) % VALUES.length];
return next;
}
public EnumColor getPrevious() {
EnumColor previous = VALUES[(ordinal() + VALUES.length - 1) % VALUES.length];
return previous;
}
public EnumColor inverse() {
return EnumColor.VALUES[15 - ordinal()];
}
public String getTag() {
return "color." + name().replace("_", ".").toLowerCase(Locale.ENGLISH);
}
public String getBasicTag() {
return name().replace("_", ".").toLowerCase(Locale.ENGLISH);
}
public String getName() {
return NAMES[ordinal()];
}
public String getLocalizedName() {
return StatCollector.translateToLocal(getTag());
}
public String getDye() {
return DYES[ordinal()];
}
@Override
public String toString() {
String s = name().replace("_", " ");
String[] words = s.split(" ");
StringBuilder b = new StringBuilder();
for (String word : words) {
b.append(word.charAt(0)).append(word.substring(1).toLowerCase(Locale.ENGLISH)).append(" ");
}
return b.toString().trim();
}
@SideOnly(Side.CLIENT)
public static void registerIcons(IIconRegister iconRegister) {
brushIcons = new IIcon[16];
for (EnumColor c : values()) {
brushIcons[c.ordinal()] = iconRegister.registerIcon("buildcraft:triggers/color_"
+ c.name().toLowerCase(Locale.ENGLISH));
}
}
@SideOnly(Side.CLIENT)
public IIcon getIcon() {
return brushIcons [ordinal()];
}
}