9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2026-01-06 15:51:31 +00:00
Files
Leaf/patches/server/0037-Faster-Natural-Spawning.patch
2023-09-23 15:38:17 -04:00

94 lines
5.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Thu, 21 Sep 2023 02:56:22 -0400
Subject: [PATCH] Faster Natural Spawning
diff --git a/src/main/java/net/minecraft/util/RandomSource.java b/src/main/java/net/minecraft/util/RandomSource.java
index ff1ad1024419182f7f3de578442c1c033d4c9ebb..5e51a1c79811291a740ad4d5e79a7d672f4a2ab6 100644
--- a/src/main/java/net/minecraft/util/RandomSource.java
+++ b/src/main/java/net/minecraft/util/RandomSource.java
@@ -16,6 +16,12 @@ public interface RandomSource {
return create(RandomSupport.generateUniqueSeed());
}
+ // Leaf start - Generate random seed faster
+ static RandomSource createFaster() {
+ return create(RandomSupport.generateFasterSeed());
+ }
+ // Leaf end
+
/** @deprecated */
@Deprecated
static RandomSource createThreadSafe() {
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index 97c7e9c8dc2dc3860de4e697ecd2c1179ef6fd56..4a6528cbc2810032cce96bf7228e9075def0c18d 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -125,6 +125,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
protected float oThunderLevel;
public float thunderLevel;
public final RandomSource random = RandomSource.create();
+ public final RandomSource randomFaster = RandomSource.createFaster(); // Leaf - Generate random seed faster
/** @deprecated */
@Deprecated
private final RandomSource threadSafeRandom = RandomSource.createThreadSafe();
diff --git a/src/main/java/net/minecraft/world/level/NaturalSpawner.java b/src/main/java/net/minecraft/world/level/NaturalSpawner.java
index 8126bd60d5075e344df77add0a38f73c53b3bdd1..6fb5da6f8def49c80a56b4ad583bf54801cd378d 100644
--- a/src/main/java/net/minecraft/world/level/NaturalSpawner.java
+++ b/src/main/java/net/minecraft/world/level/NaturalSpawner.java
@@ -429,11 +429,13 @@ public final class NaturalSpawner {
private static BlockPos getRandomPosWithin(ServerLevel world, LevelChunk chunk) { // Gale - Airplane - Use ThreadUnsafeRandom for mob spawning - accept ServerLevel
ChunkPos chunkcoordintpair = chunk.getPos();
// Gale start - Airplane - Use ThreadUnsafeRandom for mob spawning - use ThreadUnsafeRandom
- int i = chunkcoordintpair.getMinBlockX() + world.randomTickRandom.nextInt(16);
- int j = chunkcoordintpair.getMinBlockZ() + world.randomTickRandom.nextInt(16);
+ // Leaf start - Generate random seed faster
+ int i = chunkcoordintpair.getMinBlockX() + world.randomFaster.nextInt(16);
+ int j = chunkcoordintpair.getMinBlockZ() + world.randomFaster.nextInt(16);
// Gale end - Airplane - Use ThreadUnsafeRandom for mob spawning - use ThreadUnsafeRandom
int k = chunk.getHeight(Heightmap.Types.WORLD_SURFACE, i, j) + 1;
- int l = Mth.randomBetweenInclusive(world.randomTickRandom, world.getMinBuildHeight(), k); // Gale - Airplane - Use ThreadUnsafeRandom for mob spawning - use ThreadUnsafeRandom
+ int l = Mth.randomBetweenInclusive(world.randomFaster, world.getMinBuildHeight(), k); // Gale - Airplane - Use ThreadUnsafeRandom for mob spawning - use ThreadUnsafeRandom
+ // Leaf end
return new BlockPos(i, l, j);
}
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..a1db988eb51c8a1f6e2ba45cc5d30b1d7b9d5c4b 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.atomic.AtomicLong;
public final class RandomSupport {
@@ -12,6 +13,10 @@ 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);
+ // Leaf start - Generate random seed faster
+ private static long FASTER_SEED_UNIQUIFIER = 8682522807148012L;
+ private static final SplittableRandom random = new SplittableRandom();
+ // Leaf end
@VisibleForTesting
public static long mixStafford13(long seed) {
@@ -43,6 +48,13 @@ public final class RandomSupport {
}) ^ System.nanoTime();
}
+ // Leaf start - Generate random seed faster
+ public static long generateFasterSeed() {
+ FASTER_SEED_UNIQUIFIER *= 1181783497276652981L;
+ return FASTER_SEED_UNIQUIFIER ^ random.nextLong();
+ }
+ // Leaf end
+
public static record Seed128bit(long seedLo, long seedHi) {
public RandomSupport.Seed128bit xor(long seedLo, long seedHi) {
return new RandomSupport.Seed128bit(this.seedLo ^ seedLo, this.seedHi ^ seedHi);