11package cn .nukkit .utils ;
22
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+
310public enum DyeColor {
411
512
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 ) );
2229
2330
2431 private int dyeColorMeta ;
32+ private int itemDyeMeta ;
2533 private int woolColorMeta ;
2634 private String colorName ;
2735 private String dyeName ;
2836 private BlockColor blockColor ;
37+ private BlockColor leatherColor ;
2938
3039
3140 private final static DyeColor [] BY_WOOL_DATA ;
3241 private final static DyeColor [] BY_DYE_DATA ;
3342
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 );
3653 }
3754
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 ) {
3956 this .dyeColorMeta = dyeColorMeta ;
4057 this .woolColorMeta = woolColorMeta ;
58+ this .itemDyeMeta = itemDyeMeta ;
4159 this .colorName = colorName ;
4260 this .blockColor = blockColor ;
4361 this .dyeName = dyeName ;
62+ this .leatherColor = leatherColor ;
4463 }
4564
4665 public BlockColor getColor () {
4766 return this .blockColor ;
4867 }
4968
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+ */
5073 public int getDyeData () {
5174 return this .dyeColorMeta ;
5275 }
5376
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+
5493 public int getWoolData () {
5594 return this .woolColorMeta ;
5695 }
@@ -64,17 +103,22 @@ public String getDyeName() {
64103 }
65104
66105 static {
67- BY_DYE_DATA = values ();
68106 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+ }
69113
70114 for (DyeColor color : values ()) {
71115 BY_WOOL_DATA [color .woolColorMeta & 0x0f ] = color ;
72- BY_DYE_DATA [color .dyeColorMeta & 0x0f ] = color ;
73116 }
74117 }
75118
119+ @ PowerNukkitDifference (since = "1.4.0.0-PN" , info = "When overflowed, instead of wrapping, the meta will be clamped, accepts the new dye metas" )
76120 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 ) ];
78122 }
79123
80124 public static DyeColor getByWoolData (int woolColorMeta ) {
0 commit comments