forked from SteamWar/SteamWar
Fix ColorInit and CustomMap deprecation warnings
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
steamwar.java
|
steamwar.java
|
||||||
|
widener
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -32,6 +33,11 @@ dependencies {
|
|||||||
compileOnly(libs.fawe)
|
compileOnly(libs.fawe)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
widener {
|
||||||
|
fromCatalog(libs.nms)
|
||||||
|
fromCatalog(libs.paperapi)
|
||||||
|
}
|
||||||
|
|
||||||
tasks.register<DevServer>("DevLobby20") {
|
tasks.register<DevServer>("DevLobby20") {
|
||||||
group = "run"
|
group = "run"
|
||||||
description = "Run a 1.20 Dev Lobby"
|
description = "Run a 1.20 Dev Lobby"
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class ColorInit {
|
|||||||
if (inputStream == null) {
|
if (inputStream == null) {
|
||||||
colors = new byte[256 * 256 * 256];
|
colors = new byte[256 * 256 * 256];
|
||||||
for (int i = 0; i < colors.length; i++) {
|
for (int i = 0; i < colors.length; i++) {
|
||||||
colors[i] = MapPalette.matchColor(new Color(i));
|
colors[i] = matchColor(new Color(i));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
@@ -57,4 +57,26 @@ public class ColorInit {
|
|||||||
}
|
}
|
||||||
System.out.println("[ColorInit] Initialization took " + (System.currentTimeMillis() - time) + "ms");
|
System.out.println("[ColorInit] Initialization took " + (System.currentTimeMillis() - time) + "ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static byte matchColor(Color color) {
|
||||||
|
if (color.getAlpha() < 128) return 0;
|
||||||
|
|
||||||
|
if (MapPalette.mapColorCache != null && MapPalette.mapColorCache.isCached()) {
|
||||||
|
return MapPalette.mapColorCache.matchColor(color);
|
||||||
|
}
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
double best = -1;
|
||||||
|
|
||||||
|
for (int i = 4; i < MapPalette.colors.length; i++) {
|
||||||
|
double distance = MapPalette.getDistance(color, MapPalette.colors[i]);
|
||||||
|
if (distance < best || best == -1) {
|
||||||
|
best = distance;
|
||||||
|
index = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Minecraft has 248 colors, some of which have negative byte representations
|
||||||
|
return (byte) (index < 128 ? index : -129 + (index - 127));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -254,7 +254,8 @@ public class CustomMap implements Listener {
|
|||||||
int green = pixels[i2];
|
int green = pixels[i2];
|
||||||
int i3 = (y * width + x) * numBands + 2;
|
int i3 = (y * width + x) * numBands + 2;
|
||||||
int blue = pixels[i3];
|
int blue = pixels[i3];
|
||||||
Color nearest = MapPalette.getColor(ColorInit.getColorByte(red, green, blue));
|
int colorIndex = ColorInit.getColorByte(red, green, blue);
|
||||||
|
Color nearest = MapPalette.colors[colorIndex >= 0 ? colorIndex : colorIndex + 256];
|
||||||
|
|
||||||
pixels[(y * width + x) * numBands] = nearest.getRed();
|
pixels[(y * width + x) * numBands] = nearest.getRed();
|
||||||
pixels[i2] = nearest.getGreen();
|
pixels[i2] = nearest.getGreen();
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
accessWidener v2 named
|
||||||
|
|
||||||
|
# For CustomMap and ColorInit
|
||||||
|
accessible field org/bukkit/map/MapPalette colors [Ljava/awt/Color;
|
||||||
|
accessible method org/bukkit/map/MapPalette getDistance (Ljava/awt/Color;Ljava/awt/Color;)D
|
||||||
|
accessible field org/bukkit/map/MapPalette mapColorCache Lorg/bukkit/map/MapPalette$MapColorCache;
|
||||||
Reference in New Issue
Block a user