mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
90 lines
5.2 KiB
Diff
90 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 1916e5f1d6bc4c2b14a138a46477adea939caf81..275557da9faa7f27dd2fbfbdfbda620d4add0f8a 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 ec6afe51fd204e4c0764850dcc4535f7f8c159ab..9f8c6fa8fdf83ecc1e2582345bcf6bb757577f60 100644
|
|
--- a/src/main/java/net/minecraft/world/level/NaturalSpawner.java
|
|
+++ b/src/main/java/net/minecraft/world/level/NaturalSpawner.java
|
|
@@ -426,12 +426,12 @@ 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);
|
|
+ // Gale start - Airplane - Use ThreadUnsafeRandom for mob spawning - use ThreadUnsafeRandom // 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..98698c04d1cfbaccff67a17045b219fba65626d6 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,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 {
|
|
}) ^ System.nanoTime();
|
|
}
|
|
|
|
+ // Leaf start - Generate random seed faster
|
|
+ public static long generateFasterSeed() {
|
|
+ return SEED_UNIQUIFIER.updateAndGet((seedUniquifier) -> seedUniquifier * 1181783497276652981L)^ 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);
|