1
1
package cn .nukkit .utils ;
2
2
3
+ import cn .nukkit .api .PowerNukkitDifference ;
4
+ import cn .nukkit .api .PowerNukkitOnly ;
5
+ import cn .nukkit .api .Since ;
6
+ import cn .nukkit .math .MathHelper ;
7
+
8
+ import java .util .Arrays ;
9
+
3
10
public enum DyeColor {
4
11
5
12
6
- BLACK (0 , 15 , "Black" , "Ink Sack" , BlockColor .BLACK_BLOCK_COLOR ),
7
- RED (1 , 14 , "Red" , "Rose Red" , BlockColor .RED_BLOCK_COLOR ),
8
- GREEN (2 , 13 , "Green" , "Cactus Green" , BlockColor .GREEN_BLOCK_COLOR ),
9
- BROWN (3 , 12 , "Brown" , "Cocoa Beans" , BlockColor .BROWN_BLOCK_COLOR ),
10
- BLUE (4 , 11 , "Blue" , "Lapis Lazuli" , BlockColor .BLUE_BLOCK_COLOR ),
11
- PURPLE (5 , 10 , "Purple" , BlockColor .PURPLE_BLOCK_COLOR ),
12
- CYAN (6 , 9 , "Cyan" , BlockColor .CYAN_BLOCK_COLOR ),
13
- LIGHT_GRAY (7 , 8 , "Light Gray" , BlockColor .LIGHT_GRAY_BLOCK_COLOR ),
14
- GRAY (8 , 7 , "Gray" , BlockColor .GRAY_BLOCK_COLOR ),
15
- PINK (9 , 6 , "Pink" , BlockColor .PINK_BLOCK_COLOR ),
16
- LIME (10 , 5 , "Lime" , BlockColor .LIME_BLOCK_COLOR ),
17
- YELLOW (11 , 4 , "Yellow" , "Dandelion Yellow" , BlockColor .YELLOW_BLOCK_COLOR ),
18
- LIGHT_BLUE (12 , 3 , "Light Blue" , BlockColor .LIGHT_BLUE_BLOCK_COLOR ),
19
- MAGENTA (13 , 2 , "Magenta" , BlockColor .MAGENTA_BLOCK_COLOR ),
20
- ORANGE (14 , 1 , "Orange" , BlockColor .ORANGE_BLOCK_COLOR ),
21
- WHITE (15 , 0 , "White" , "Bone Meal" , BlockColor .WHITE_BLOCK_COLOR );
13
+ BLACK (0 , 15 , 16 , "Black" , "Ink Sack" , BlockColor .BLACK_BLOCK_COLOR , new BlockColor ( 0x1D1D21 ) ),
14
+ RED (1 , 14 , 1 , "Red" , "Rose Red" , BlockColor .RED_BLOCK_COLOR , new BlockColor ( 0xB02E26 ) ),
15
+ GREEN (2 , 13 , 2 , "Green" , "Cactus Green" , BlockColor .GREEN_BLOCK_COLOR , new BlockColor ( 0x5E7C16 ) ),
16
+ BROWN (3 , 12 , 17 , "Brown" , "Cocoa Beans" , BlockColor .BROWN_BLOCK_COLOR , new BlockColor ( 0x835432 ) ),
17
+ BLUE (4 , 11 , 18 , "Blue" , "Lapis Lazuli" , BlockColor .BLUE_BLOCK_COLOR , new BlockColor ( 0x3C44AA ) ),
18
+ PURPLE (5 , 10 , 5 , "Purple" , BlockColor .PURPLE_BLOCK_COLOR , new BlockColor ( 0x8932B8 ) ),
19
+ CYAN (6 , 9 , 6 , "Cyan" , BlockColor .CYAN_BLOCK_COLOR , new BlockColor ( 0x169C9C ) ),
20
+ LIGHT_GRAY (7 , 8 , 7 , "Light Gray" , BlockColor .LIGHT_GRAY_BLOCK_COLOR , new BlockColor ( 0x9D9D97 ) ),
21
+ GRAY (8 , 7 , 8 , "Gray" , BlockColor .GRAY_BLOCK_COLOR , new BlockColor ( 0x474F52 ) ),
22
+ PINK (9 , 6 , 9 , "Pink" , BlockColor .PINK_BLOCK_COLOR , new BlockColor ( 0xF38BAA ) ),
23
+ LIME (10 , 5 , 10 , "Lime" , BlockColor .LIME_BLOCK_COLOR , new BlockColor ( 0x80C71F ) ),
24
+ YELLOW (11 , 4 , 11 , "Yellow" , "Dandelion Yellow" , BlockColor .YELLOW_BLOCK_COLOR , new BlockColor ( 0xFED83D ) ),
25
+ LIGHT_BLUE (12 , 3 , 12 , "Light Blue" , BlockColor .LIGHT_BLUE_BLOCK_COLOR , new BlockColor ( 0x3AB3DA ) ),
26
+ MAGENTA (13 , 2 , 13 , "Magenta" , BlockColor .MAGENTA_BLOCK_COLOR , new BlockColor ( 0xC74EBD ) ),
27
+ ORANGE (14 , 1 , 14 , "Orange" , BlockColor .ORANGE_BLOCK_COLOR , new BlockColor ( 0xFF9801 ) ),
28
+ WHITE (15 , 0 , 19 , "White" , "Bone Meal" , BlockColor .WHITE_BLOCK_COLOR , new BlockColor ( 0xF0F0F0 ) );
22
29
23
30
24
31
private int dyeColorMeta ;
32
+ private int itemDyeMeta ;
25
33
private int woolColorMeta ;
26
34
private String colorName ;
27
35
private String dyeName ;
28
36
private BlockColor blockColor ;
37
+ private BlockColor leatherColor ;
29
38
30
39
31
40
private final static DyeColor [] BY_WOOL_DATA ;
32
41
private final static DyeColor [] BY_DYE_DATA ;
33
42
34
- DyeColor (int dyeColorMeta , int woolColorMeta , String colorName , BlockColor blockColor ) {
35
- this (dyeColorMeta , woolColorMeta , colorName , colorName + " Dye" , blockColor );
43
+ DyeColor (int dyeColorMeta , int woolColorMeta , int itemDyeMeta , String colorName , BlockColor blockColor ) {
44
+ this (dyeColorMeta , woolColorMeta , itemDyeMeta , colorName , blockColor , blockColor );
45
+ }
46
+
47
+ DyeColor (int dyeColorMeta , int woolColorMeta , int itemDyeMeta , String colorName , BlockColor blockColor , BlockColor leatherColor ) {
48
+ this (dyeColorMeta , woolColorMeta , itemDyeMeta , colorName , colorName + " Dye" , blockColor , leatherColor );
49
+ }
50
+
51
+ DyeColor (int dyeColorMeta , int woolColorMeta , int itemDyeMeta , String colorName , String dyeName , BlockColor blockColor ) {
52
+ this (dyeColorMeta , woolColorMeta , itemDyeMeta , colorName , blockColor , blockColor );
36
53
}
37
54
38
- DyeColor (int dyeColorMeta , int woolColorMeta , String colorName , String dyeName , BlockColor blockColor ) {
55
+ DyeColor (int dyeColorMeta , int woolColorMeta , int itemDyeMeta , String colorName , String dyeName , BlockColor blockColor , BlockColor leatherColor ) {
39
56
this .dyeColorMeta = dyeColorMeta ;
40
57
this .woolColorMeta = woolColorMeta ;
58
+ this .itemDyeMeta = itemDyeMeta ;
41
59
this .colorName = colorName ;
42
60
this .blockColor = blockColor ;
43
61
this .dyeName = dyeName ;
62
+ this .leatherColor = leatherColor ;
44
63
}
45
64
46
65
public BlockColor getColor () {
47
66
return this .blockColor ;
48
67
}
49
68
69
+ /**
70
+ * The {@code minecraft:dye} meta from `0-15` that represents the source of a dye. Includes
71
+ * ink_sac, bone_meal, cocoa_beans, and lapis_lazuli.
72
+ */
50
73
public int getDyeData () {
51
74
return this .dyeColorMeta ;
52
75
}
53
76
77
+ /**
78
+ * The {@code minecraft:dye} meta that actually represents the item dye for that color.
79
+ * Uses black_dye instead of ink_sac, white_dye instead of bone_meal, and so on.
80
+ */
81
+ @ PowerNukkitOnly
82
+ @ Since ("1.4.0.0-PN" )
83
+ public int getItemDyeMeta () {
84
+ return itemDyeMeta ;
85
+ }
86
+
87
+ @ PowerNukkitOnly
88
+ @ Since ("1.4.0.0-PN" )
89
+ public BlockColor getLeatherColor () {
90
+ return leatherColor ;
91
+ }
92
+
54
93
public int getWoolData () {
55
94
return this .woolColorMeta ;
56
95
}
@@ -64,17 +103,22 @@ public String getDyeName() {
64
103
}
65
104
66
105
static {
67
- BY_DYE_DATA = values ();
68
106
BY_WOOL_DATA = values ();
107
+ BY_DYE_DATA = new DyeColor [Arrays .stream (BY_WOOL_DATA ).mapToInt (DyeColor ::getItemDyeMeta ).max ().orElse (0 ) + 1 ];
108
+
109
+ for (DyeColor dyeColor : BY_WOOL_DATA ) {
110
+ BY_DYE_DATA [dyeColor .dyeColorMeta ] = dyeColor ;
111
+ BY_DYE_DATA [dyeColor .itemDyeMeta ] = dyeColor ;
112
+ }
69
113
70
114
for (DyeColor color : values ()) {
71
115
BY_WOOL_DATA [color .woolColorMeta & 0x0f ] = color ;
72
- BY_DYE_DATA [color .dyeColorMeta & 0x0f ] = color ;
73
116
}
74
117
}
75
118
119
+ @ PowerNukkitDifference (since = "1.4.0.0-PN" , info = "When overflowed, instead of wrapping, the meta will be clamped, accepts the new dye metas" )
76
120
public static DyeColor getByDyeData (int dyeColorMeta ) {
77
- return BY_DYE_DATA [dyeColorMeta & 0x0f ];
121
+ return BY_DYE_DATA [MathHelper . clamp ( dyeColorMeta , 0 , BY_DYE_DATA . length - 1 ) ];
78
122
}
79
123
80
124
public static DyeColor getByWoolData (int woolColorMeta ) {
0 commit comments