3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-27 00:23:03 +01:00

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

Dieser Commit ist enthalten in:
Gerrygames 2020-04-25 22:46:24 +02:00 committet von GitHub
Ursprung 6cfcab88d3
Commit 74f869beb5
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 11 neuen und 17 gelöschten Zeilen

Datei anzeigen

@ -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>

Datei anzeigen

@ -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);

Datei anzeigen

@ -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);
} }
} }