Yatopia/patches/api/0012-fixup-Optimise-Bukkit-s-MapPalette.patch
2020-12-26 12:18:16 +02:00

101 lines
4.3 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ivan Pekov <ivan@mrivanplays.com>
Date: Sat, 26 Dec 2020 12:14:12 +0200
Subject: [PATCH] fixup! Optimise Bukkit's MapPalette
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index 7b704b5841aa2f212b70719cf9bd79b4fb21fcf0..2e4795be4eadd20c24e058850b6d35b6a6de1f3c 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -1837,5 +1837,6 @@ public final class Bukkit {
public static java.time.Duration getLastTickTime() {
return server.getLastTickTime();
}
+ public static java.awt.Color[] getVanillaMapColors() { return server.getVanillaMapColors(); }
// Yatopia end
}
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index 2f86ada4a487a6d59fa8b173c8339dcdda65cb30..0b5db06d26e69f7bff36ec12c5155634e2c56c37 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -1669,5 +1669,12 @@ public interface Server extends PluginMessageRecipient {
* @return duration
*/
java.time.Duration getLastTickTime();
+
+ /**
+ * Returns the vanilla declared map colors.
+ *
+ * @return vanilla map colors
+ */
+ java.awt.Color[] getVanillaMapColors();
// Yatopia end
}
diff --git a/src/main/java/org/bukkit/map/MapPalette.java b/src/main/java/org/bukkit/map/MapPalette.java
index 84daffdda568039423d0f6d18981bb9d9a392e1f..0bff82448b8c677027bd95d67d46c7526d720dcb 100644
--- a/src/main/java/org/bukkit/map/MapPalette.java
+++ b/src/main/java/org/bukkit/map/MapPalette.java
@@ -127,8 +127,8 @@ public final class MapPalette {
// getting an array of rgb values of each color
rgbColors = java.util.Arrays.stream(colors).mapToInt(Color::getRGB).toArray();
+ /*
try {
- // load net.minecraft.server.MaterialMapColor class. using reflection because build fails. maven thinks nms isn't accessible from Yatopia-API
Class<?> materialMapColorClass = MapPalette.class.getClassLoader().loadClass("net.minecraft.server.MaterialMapColor");
// get vanilla colors
Object[] vanillaColorObjects = (Object[]) java.util.Arrays.stream(materialMapColorClass.getFields()).filter(f -> f.getType().isArray() && f.getType().getComponentType().equals(materialMapColorClass)).findAny().get().get(null);
@@ -157,6 +157,19 @@ public final class MapPalette {
} catch (Exception ex) {
throw new RuntimeException(ex);
}
+ */
+ vanillaColors = org.bukkit.Bukkit.getVanillaMapColors();
+ doubleColors = new Color[vanillaColors.length][modifiers.length];
+ for (int i = 0; i < vanillaColors.length; i++) {
+ Color vanillaColor = vanillaColors[i];
+ for (int j = 0; j < modifiers.length; j++) {
+ int modifier = modifiers[j];
+ int mr = vanillaColor.getRed() * modifier / 255;
+ int mg = vanillaColor.getGreen() * modifier / 255;
+ int mb = vanillaColor.getBlue() * modifier / 255;
+ doubleColors[i][j] = c(mr, mg, mb);
+ }
+ }
}
// Yatopia end
@@ -299,9 +312,9 @@ public final class MapPalette {
public static byte matchColor(@NotNull Color color) {
if (color.getAlpha() < 128) return 0;
+ int index = 0;
// Yatopia start - foreach a maximum of 62 colors instead of 236 per pixel
/*
- int index = 0;
double best = -1;
for (int i = 4; i < colors.length; i++) {
@@ -313,7 +326,6 @@ public final class MapPalette {
}
*/
- int index = 0;
int best = -1;
for (int i = 0; i < vanillaColors.length; i++) {
@@ -342,10 +354,12 @@ public final class MapPalette {
}
index = com.google.common.primitives.Ints.indexOf(rgbColors, modColors[index].getRGB());
+ /*
// we have already checked if color is transparent so now there aren't any transparent colors
// and if (index < 4) then nearest color was black (hex #000000), so we need to return the most black color
if (index < 4)
index = 119;
+ */
// Yatopia end
// Minecraft has 143 colors, some of which have negative byte representations