From 6e5e72d5c36d77df72ce2574785e0fe94c5f3c22 Mon Sep 17 00:00:00 2001 From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> Date: Mon, 9 Oct 2023 21:36:50 -0400 Subject: [PATCH] Use thread-safe ThreadLocalRandom --- .../server/0032-Faster-Natural-Spawning.patch | 16 +++-------- ...ndom-for-xaeroMapServerID-generation.patch | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 patches/server/0033-Faster-Random-for-xaeroMapServerID-generation.patch diff --git a/patches/server/0032-Faster-Natural-Spawning.patch b/patches/server/0032-Faster-Natural-Spawning.patch index b4c57e0b..f8b23643 100644 --- a/patches/server/0032-Faster-Natural-Spawning.patch +++ b/patches/server/0032-Faster-Natural-Spawning.patch @@ -55,32 +55,24 @@ index ec6afe51fd204e4c0764850dcc4535f7f8c159ab..9f8c6fa8fdf83ecc1e2582345bcf6bb7 } diff --git a/src/main/java/net/minecraft/world/level/levelgen/RandomSupport.java b/src/main/java/net/minecraft/world/level/levelgen/RandomSupport.java -index 36f9d68b70fbd1cd3790a9bb5a729a11da8cbf83..98698c04d1cfbaccff67a17045b219fba65626d6 100644 +index 36f9d68b70fbd1cd3790a9bb5a729a11da8cbf83..458ef9e6f68f89f34a9e1bd74b50d52eeb93342e 100644 --- a/src/main/java/net/minecraft/world/level/levelgen/RandomSupport.java +++ b/src/main/java/net/minecraft/world/level/levelgen/RandomSupport.java @@ -5,6 +5,7 @@ import com.google.common.base.Charsets; import com.google.common.hash.HashFunction; import com.google.common.hash.Hashing; import com.google.common.primitives.Longs; -+import java.util.SplittableRandom; ++import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.atomic.AtomicLong; public final class RandomSupport { -@@ -12,6 +13,7 @@ public final class RandomSupport { - public static final long SILVER_RATIO_64 = 7640891576956012809L; - private static final HashFunction MD5_128 = Hashing.md5(); - private static final AtomicLong SEED_UNIQUIFIER = new AtomicLong(8682522807148012L); -+ private static final SplittableRandom random = new SplittableRandom(); // Leaf - Generate random seed faster - - @VisibleForTesting - public static long mixStafford13(long seed) { -@@ -43,6 +45,12 @@ public final class RandomSupport { +@@ -43,6 +44,12 @@ public final class RandomSupport { }) ^ System.nanoTime(); } + // Leaf start - Generate random seed faster + public static long generateFasterSeed() { -+ return SEED_UNIQUIFIER.updateAndGet((seedUniquifier) -> seedUniquifier * 1181783497276652981L)^ random.nextLong(); ++ return SEED_UNIQUIFIER.updateAndGet((seedUniquifier) -> seedUniquifier * 1181783497276652981L)^ ThreadLocalRandom.current().nextLong(); + } + // Leaf end + diff --git a/patches/server/0033-Faster-Random-for-xaeroMapServerID-generation.patch b/patches/server/0033-Faster-Random-for-xaeroMapServerID-generation.patch new file mode 100644 index 00000000..e61ba322 --- /dev/null +++ b/patches/server/0033-Faster-Random-for-xaeroMapServerID-generation.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> +Date: Mon, 9 Oct 2023 21:33:08 -0400 +Subject: [PATCH] Faster Random for xaeroMapServerID generation + + +diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java +index 245bf3d0c17e91c24ff28e53f0ee73b66b4d5e50..c9e57d0b97797aef9008cbdeeb4ab2a8bf51ea59 100644 +--- a/src/main/java/org/dreeam/leaf/LeafConfig.java ++++ b/src/main/java/org/dreeam/leaf/LeafConfig.java +@@ -1,7 +1,7 @@ + package org.dreeam.leaf; + + import com.google.common.collect.ImmutableMap; +-import java.util.Random; ++import java.util.concurrent.ThreadLocalRandom; + import net.minecraft.server.MinecraftServer; + import org.bukkit.Bukkit; + import org.bukkit.configuration.ConfigurationSection; +@@ -206,7 +206,7 @@ public class LeafConfig { + public static boolean jadeProtocol = false; + public static boolean appleskinProtocol = false; + public static boolean xaeroMapProtocol = false; +- public static int xaeroMapServerID = new Random().nextInt(); ++ public static int xaeroMapServerID = ThreadLocalRandom.current().nextInt(); // Leaf - Faster Random + private static void network() { + jadeProtocol = getBoolean("network.protocol.jade-protocol", jadeProtocol); + appleskinProtocol = getBoolean("network.protocol.appleskin-protocol", appleskinProtocol);