3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 16:12:46 +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>
<groupId>com.nukkitx.protocol</groupId>
<artifactId>bedrock-v390</artifactId>
<version>2.5.5</version>
<version>2.5.6-SNAPSHOT</version>
<scope>compile</scope>
<exclusions>
<exclusion>

Datei anzeigen

@ -51,13 +51,12 @@ public class JavaMapDataTranslator extends PacketTranslator<ServerMapDataPacket>
mapItemDataPacket.setWidth(data.getColumns());
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 idx = 0;
for (byte colorId : data.getData()) {
colors[idx] = MapColor.fromId(colorId).toARGB();
idx++;
colors[idx++] = MapColor.fromId(colorId & 0xFF).toABGR();
}
mapItemDataPacket.setColors(colors);

Datei anzeigen

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