github.com/df-mc/dragonfly@v0.9.13/server/item/colour.go (about) 1 package item 2 3 import ( 4 "image/color" 5 ) 6 7 // Colour represents the colour of a block. Typically, Minecraft blocks have a total of 16 different colours. 8 type Colour struct { 9 colour 10 } 11 12 // ColourWhite returns the white colour. 13 func ColourWhite() Colour { 14 return Colour{0} 15 } 16 17 // ColourOrange returns the orange colour. 18 func ColourOrange() Colour { 19 return Colour{1} 20 } 21 22 // ColourMagenta returns the magenta colour. 23 func ColourMagenta() Colour { 24 return Colour{2} 25 } 26 27 // ColourLightBlue returns the light blue colour. 28 func ColourLightBlue() Colour { 29 return Colour{3} 30 } 31 32 // ColourYellow returns the yellow colour. 33 func ColourYellow() Colour { 34 return Colour{4} 35 } 36 37 // ColourLime returns the lime colour. 38 func ColourLime() Colour { 39 return Colour{5} 40 } 41 42 // ColourPink returns the pink colour. 43 func ColourPink() Colour { 44 return Colour{6} 45 } 46 47 // ColourGrey returns the grey colour. 48 func ColourGrey() Colour { 49 return Colour{7} 50 } 51 52 // ColourLightGrey returns the light grey colour. 53 func ColourLightGrey() Colour { 54 return Colour{8} 55 } 56 57 // ColourCyan returns the cyan colour. 58 func ColourCyan() Colour { 59 return Colour{9} 60 } 61 62 // ColourPurple returns the purple colour. 63 func ColourPurple() Colour { 64 return Colour{10} 65 } 66 67 // ColourBlue returns the blue colour. 68 func ColourBlue() Colour { 69 return Colour{11} 70 } 71 72 // ColourBrown returns the brown colour. 73 func ColourBrown() Colour { 74 return Colour{12} 75 } 76 77 // ColourGreen returns the green colour. 78 func ColourGreen() Colour { 79 return Colour{13} 80 } 81 82 // ColourRed returns the red colour. 83 func ColourRed() Colour { 84 return Colour{14} 85 } 86 87 // ColourBlack returns the black colour. 88 func ColourBlack() Colour { 89 return Colour{15} 90 } 91 92 // Colours returns a list of all existing colours. 93 func Colours() []Colour { 94 return []Colour{ 95 ColourWhite(), ColourOrange(), ColourMagenta(), ColourLightBlue(), ColourYellow(), ColourLime(), ColourPink(), ColourGrey(), 96 ColourLightGrey(), ColourCyan(), ColourPurple(), ColourBlue(), ColourBrown(), ColourGreen(), ColourRed(), ColourBlack(), 97 } 98 } 99 100 // colour is the underlying value of a Colour struct. 101 type colour uint8 102 103 // RGBA returns the colour as RGBA. The alpha channel is always set to the maximum value. Colour values as returned here 104 // were obtained by placing signs in a world with all possible dyes used on them. The world was then loaded in Dragonfly 105 // to read their respective colours. 106 func (c colour) RGBA() color.RGBA { 107 switch c { 108 case 0: 109 return color.RGBA{R: 0xf0, G: 0xf0, B: 0xf0, A: 0xff} 110 case 1: 111 return color.RGBA{R: 0xf9, G: 0x80, B: 0x1d, A: 0xff} 112 case 2: 113 return color.RGBA{R: 0xc7, G: 0x4e, B: 0xbd, A: 0xff} 114 case 3: 115 return color.RGBA{R: 0x3a, G: 0xb3, B: 0xda, A: 0xff} 116 case 4: 117 return color.RGBA{R: 0xfe, G: 0xd8, B: 0x3d, A: 0xff} 118 case 5: 119 return color.RGBA{R: 0x80, G: 0xc7, B: 0x1f, A: 0xff} 120 case 6: 121 return color.RGBA{R: 0xf3, G: 0x8b, B: 0xaa, A: 0xff} 122 case 7: 123 return color.RGBA{R: 0x47, G: 0x4f, B: 0x52, A: 0xff} 124 case 8: 125 return color.RGBA{R: 0x9d, G: 0x9d, B: 0x97, A: 0xff} 126 case 9: 127 return color.RGBA{R: 0x16, G: 0x9c, B: 0x9c, A: 0xff} 128 case 10: 129 return color.RGBA{R: 0x89, G: 0x32, B: 0xb8, A: 0xff} 130 case 11: 131 return color.RGBA{R: 0x3c, G: 0x44, B: 0xaa, A: 0xff} 132 case 12: 133 return color.RGBA{R: 0x83, G: 0x54, B: 0x32, A: 0xff} 134 case 13: 135 return color.RGBA{R: 0x5e, G: 0x7c, B: 0x16, A: 0xff} 136 case 14: 137 return color.RGBA{R: 0xb0, G: 0x2e, B: 0x26, A: 0xff} 138 default: 139 return color.RGBA{R: 0x00, G: 0x00, B: 0x00, A: 0xff} 140 } 141 } 142 143 // String ... 144 func (c colour) String() string { 145 switch c { 146 default: 147 return "white" 148 case 1: 149 return "orange" 150 case 2: 151 return "magenta" 152 case 3: 153 return "light_blue" 154 case 4: 155 return "yellow" 156 case 5: 157 return "lime" 158 case 6: 159 return "pink" 160 case 7: 161 return "gray" 162 case 8: 163 return "light_gray" 164 case 9: 165 return "cyan" 166 case 10: 167 return "purple" 168 case 11: 169 return "blue" 170 case 12: 171 return "brown" 172 case 13: 173 return "green" 174 case 14: 175 return "red" 176 case 15: 177 return "black" 178 } 179 } 180 181 // SilverString returns the name of the colour, with light_gray being replaced by silver. 182 func (c colour) SilverString() string { 183 if c == 8 { 184 return "silver" 185 } 186 return c.String() 187 } 188 189 // Uint8 ... 190 func (c colour) Uint8() uint8 { 191 return uint8(c) 192 } 193 194 // invertColour converts the item.Colour passed and returns the colour ID inverted. 195 func invertColour(c Colour) int16 { 196 return ^int16(c.Uint8()) & 0xf 197 } 198 199 // invertColourID converts the int16 passed the returns the item.Colour inverted. 200 func invertColourID(id int16) Colour { 201 return Colours()[uint8(^id&0xf)] 202 }