Fix map colors, remove unnecessary array stream (#423)

This commit is contained in:
Gerrygames 2020-04-25 22:46:24 +02:00 committed by GitHub
parent 6cfcab88d3
commit 74f869beb5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 17 deletions

View file

@ -33,7 +33,7 @@
<dependency> <dependency>
<groupId>com.nukkitx.protocol</groupId> <groupId>com.nukkitx.protocol</groupId>
<artifactId>bedrock-v390</artifactId> <artifactId>bedrock-v390</artifactId>
<version>2.5.5</version> <version>2.5.6-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
<exclusions> <exclusions>
<exclusion> <exclusion>

View file

@ -51,13 +51,12 @@ public class JavaMapDataTranslator extends PacketTranslator<ServerMapDataPacket>
mapItemDataPacket.setWidth(data.getColumns()); mapItemDataPacket.setWidth(data.getColumns());
mapItemDataPacket.setHeight(data.getRows()); mapItemDataPacket.setHeight(data.getRows());
// Every int entry is an ARGB color // Every int entry is an ABGR color
int[] colors = new int[data.getData().length]; int[] colors = new int[data.getData().length];
int idx = 0; int idx = 0;
for (byte colorId : data.getData()) { for (byte colorId : data.getData()) {
colors[idx] = MapColor.fromId(colorId).toARGB(); colors[idx++] = MapColor.fromId(colorId & 0xFF).toABGR();
idx++;
} }
mapItemDataPacket.setColors(colors); mapItemDataPacket.setColors(colors);

View file

@ -1,7 +1,5 @@
package org.geysermc.connector.utils; package org.geysermc.connector.utils;
import java.util.Arrays;
public enum MapColor { public enum MapColor {
COLOR_0(-1, -1, -1), COLOR_0(-1, -1, -1),
COLOR_1(-1, -1, -1), COLOR_1(-1, -1, -1),
@ -212,6 +210,8 @@ public enum MapColor {
COLOR_206(37, 22, 16), COLOR_206(37, 22, 16),
COLOR_207(19, 11, 8); COLOR_207(19, 11, 8);
private static final MapColor[] VALUES = values();
private final int red; private final int red;
private final int green; private final int green;
private final int blue; private final int blue;
@ -222,23 +222,18 @@ public enum MapColor {
this.blue = blue; this.blue = blue;
} }
int getId() {
return ordinal();
}
public static MapColor fromId(int id) { public static MapColor fromId(int id) {
return Arrays.stream(values()).filter(color -> color.getId() == id).findFirst().orElse(COLOR_0); return id >= 0 && id < VALUES.length ? VALUES[id] : COLOR_0;
} }
public int toARGB() { public int toABGR() {
int alpha = 255; int alpha = 255;
if (red == -1 && green == -1 && blue == -1) if (red == -1 && green == -1 && blue == -1)
alpha = 0; // transparent alpha = 0; // transparent
long result = red & 0xff; return ((alpha & 0xFF) << 24) |
result |= (green & 0xff) << 8; ((blue & 0xFF) << 16) |
result |= (blue & 0xff) << 16; ((green & 0xFF) << 8) |
result |= (alpha & 0xff) << 24; ((red & 0xFF) << 0);
return (int) (result & 0xFFFFFFFFL);
} }
} }