mirror of
https://github.com/YatopiaMC/Yatopia.git
synced 2024-12-02 07:33:39 +01:00
Current progress
This commit is contained in:
parent
1890cf9a82
commit
cd4b222dcc
100
patches/api/0012-fixup-Optimise-Bukkit-s-MapPalette.patch
Normal file
100
patches/api/0012-fixup-Optimise-Bukkit-s-MapPalette.patch
Normal file
@ -0,0 +1,100 @@
|
||||
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
|
@ -0,0 +1,36 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Ivan Pekov <ivan@mrivanplays.com>
|
||||
Date: Sat, 26 Dec 2020 12:17:22 +0200
|
||||
Subject: [PATCH] Add a way to retrieve vanilla map colors
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
index 201d84401114864ab2f9665bda3fe09c30cc7107..1849b7204f1cbbf25811c9a4efc0a5f02b6507b4 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
@@ -269,6 +269,7 @@ public final class CraftServer implements Server {
|
||||
private final List<CraftPlayer> playerView;
|
||||
public int reloadCount;
|
||||
public static Exception excessiveVelEx; // Paper - Velocity warnings
|
||||
+ private java.awt.Color[] vanillaMapColors = null; // Yatopia
|
||||
|
||||
static {
|
||||
ConfigurationSerialization.registerClass(CraftOfflinePlayer.class);
|
||||
@@ -2473,4 +2474,17 @@ public final class CraftServer implements Server {
|
||||
// Purpur end
|
||||
|
||||
@Override public java.time.Duration getLastTickTime() { return net.minecraft.server.MinecraftServer.lastTickTime; } // Yatopia
|
||||
+
|
||||
+ // Yatopia start
|
||||
+ @Override
|
||||
+ public java.awt.Color[] getVanillaMapColors() {
|
||||
+ if (vanillaMapColors != null) {
|
||||
+ return vanillaMapColors;
|
||||
+ }
|
||||
+ vanillaMapColors = java.util.Arrays.stream(net.minecraft.server.MaterialMapColor.a)
|
||||
+ .map(c -> new java.awt.Color(c.rgb))
|
||||
+ .toArray(java.awt.Color[]::new);
|
||||
+ return vanillaMapColors;
|
||||
+ }
|
||||
+ // Yatopia end
|
||||
}
|
Loading…
Reference in New Issue
Block a user