the first 4 index of the private field MapPalette$colors are incorrect. (or at least for index 0, i don't really know if index 1, 2 and 3 should be the same or not than 0)
Prior to this commit, they would return the transparent color, and in fact the index of byte 0 sent to the client will not show any color (transparent)
Now, index 0 returns color of RGB: (0,0,0), opaque black.
It is problematic because now, byte MapPalette$matchColor(Color color) is no longer bijective with Color MapPalette$getColor(byte) in the definition domain of colors of the palette.
Example:
Color transparent = new Color(0,0,0,0);
transparent.getAlpha(); //returns 0
byte index = MapPalette.matchColor(transparent); //returns the byte 0
Color paletteTransparent = MapPalette.getColor(index); //returns Color(R:0, G:0, B:0);
paletteTransparent.getAlpha(); //returns 255, aka opaque
How have I spotted this issue?
I was working on a dithering algorithm, which basically goes through each pixel, retrieves its original RGBA value, compares it to the nearest color of the palette, and accordingly adjusts the neighbor pixels. I was surprised to see that my transparent background transformed to black, so i thought that it was due to MapPalette.matchColor(color) which was checking for the alpha channel but it does, in fact the function will return the transparent pixel if the alpha channel is <= 127, which is logical because maps only show fully opaque pixels (or the fully transparent one). I then found out about the issue I described above. For now I will add a check myself, in case index is 0 then don't try to MapPalette.getColor it, instead chose directly transparent.