9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-26 18:39:23 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0140-Faster-random-generator.patch
Dreeam 66887e3367 Update Leaf 1.21.6 (#385)
* Init 1.21.6

* Finish API patches

* Apply purpur patches & all paper server patches

* Apply some

* Apply all

* Updated Upstream (Paper/Purpur)

Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@6aafe29e 1.21.6 dev
PaperMC/Paper@ae7c74ec tweak mob goal keys, generate missing api
PaperMC/Paper@9ea1460b Revert "fix sponge-absorb deleting chest content (#12647)"

Purpur Changes:
PurpurMC/Purpur@eb0ba67d Updated Upstream (Paper)
PurpurMC/Purpur@7c6502dc Updated Upstream (Paper)
PurpurMC/Purpur@aa289e2c Updated Upstream (Paper)
PurpurMC/Purpur@b1d412fb Updated Upstream (Paper)
PurpurMC/Purpur@293e28a0 use empty registryaccess where context is not needed, closes #1676
PurpurMC/Purpur@452bb319 port PaperMC/Paper#12654, closes #1665
PurpurMC/Purpur@849bc79c register test subcommands used for debugging, closes #1675

* Fix build & diff

* Update vanilla attribute size

* [ci/skip] Forget to remove this

* Updated Upstream (Paper/Purpur)

Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@a24f9b20 1.21.6 dev
PaperMC/Paper@457a0a69 Bump version string and protocol version to 1.21.6 release
PaperMC/Paper@245b5473 Update base to 1.21.6
PaperMC/Paper@b28d77b3 Update Moonrise to 1.21.6
PaperMC/Paper@8318dcb7 Update DataConverter to 1.21.6-rc1

Purpur Changes:
PurpurMC/Purpur@b228e316 Updated Upstream (Paper)
PurpurMC/Purpur@d6562a57 make happy ghast takes-damage-from-water and always-drop-exp options work
PurpurMC/Purpur@08d989b6 inline import
PurpurMC/Purpur@61d7f559 Updated Upstream (Paper)
PurpurMC/Purpur@469a4de5 Merge branch 'ver/1.21.5' into ver/1.21.6

* Updated Upstream (Paper)

Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@d2b1158e Set correct world access on BSL snapshots

* Updated Upstream (Paper)

Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@023e6c29 Ensure waypoints are per world
PaperMC/Paper@40d5d31c Fix recursively converting JSON Text Components

* Update spigot mapping to remap reobf mapping to mojamp for plugins

* Updated Upstream (Paper/Purpur)

Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@1fcc4162 Implement FeatureHooks#isChunkSent for Moonrise chunk system
PaperMC/Paper@e4d7178a Implement WaypointTransmitter#isChunkVisible
PaperMC/Paper@8980ead7 Directly walk text component after converting from JSON
PaperMC/Paper@5613ed6d Provide env environment variable and copy spigots sys prop for overriding default repository
PaperMC/Paper@62b7f86d Avoid and discourage use of Maven Central as a CDN (#12689)
PaperMC/Paper@f5534cb7 [ci/skip] Run generators (#12691)
PaperMC/Paper@4781d28b Re-add Log4j Javadocs (#12693)
PaperMC/Paper@74fbcce5 Check type of Material in get/set stats (#12607)
PaperMC/Paper@4b3f967e Improve Fix MC-44654 (#12703)
PaperMC/Paper@a7dd2635 Enable spigot obfuscation support (#12695)
PaperMC/Paper@6a51c44e Cleanup Primed TNT Fix (#12704)
PaperMC/Paper@839c6a18 Fix #11169 (#12706)
PaperMC/Paper@c77d5f99 Fix MC-297591
PaperMC/Paper@219f86ee Implement chunk unload delay config option
PaperMC/Paper@e4eb69b8 Do not allow ticket level decreases to be processed asynchronously
PaperMC/Paper@71b0c768 Adds support for vanilla negative explosions (#12705)
PaperMC/Paper@3750927a [ci/skip] Fix PermissionManager#clearPermissions() docs bad wording (#12657)
PaperMC/Paper@d61a51e8 Add ItemType#getBurnDuration() (#12604)
PaperMC/Paper@29fc8532 Allow empty paths in namespaced keys (#12687)
PaperMC/Paper@4419afb9 fix: Safely handle nanosecond overflow in ClickCallback (#12686)
PaperMC/Paper@56528821 Add `isProxyEnabled` method to ServerConfiguration (#12664)
PaperMC/Paper@c0dda0ea Add `isForceDefaultGameMode` method (#12673)
PaperMC/Paper@e714de63 Fix excess slot updates
PaperMC/Paper@6d0821d2 [ci/skip] Fix docs for Spawner class and cleanup (#12710)
PaperMC/Paper@cceffe3d Release ItemType and BlockType (#12708)
PaperMC/Paper@186e9e33 Relocate CommandMap#registerServerAliases() call to after lifecycle events have been run (#12601)
PaperMC/Paper@5edcf6dd Cleanup/command dispatching (#12713)

Purpur Changes:
PurpurMC/Purpur@baa196f5 Updated Upstream (Paper)
PurpurMC/Purpur@fdd1e980 Updated Upstream (Paper)
PurpurMC/Purpur@439f15db Updated Upstream (Paper)
PurpurMC/Purpur@46a28b93 [ci/skip] update version in README
PurpurMC/Purpur@162bd288 Updated Upstream (Paper)
PurpurMC/Purpur@afcdf9bb Updated Upstream (Paper)

* fix random tick order

Signed-off-by: hayanesuru <hayanesuru@outlook.jp>

* update optimize random tick

* fix mob spawning over limit

* optimize mob spawning

* fix FastBitRadixSort memory leak

* optimize brain collections

* [ci/skip] update comments

* Revert "fix FastBitRadixSort memory leak"

This reverts commit bdea683525.

* optimize brain collections

* fix async mob spawning data race

* [ci/skip] cleanup

* remove hash lookup in optimize random tick

* Updated Upstream (Paper/Purpur)

Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@803baf0b Support hidden entities in Waypoints (#12715)
PaperMC/Paper@1814d8b4 build: publish to fill (#12717)
PaperMC/Paper@e454fef4 Add support for private constructors in plugin main classes (#12652)
PaperMC/Paper@d0e808f4 Move player to correct position in vehicle move packet handler
PaperMC/Paper@46b4b0b8 Improve keepalive ping system
PaperMC/Paper@38c1ddb5 Add and use FeatureHooks.getAllEntities
PaperMC/Paper@2f083acb Ensure player entity schedulers are ticked when they are dead
PaperMC/Paper@7c90c7c4 Optimise EntityScheduler ticking
PaperMC/Paper@aa6ee44a Re-add global region scheduler tick erroneously removed in last commit
PaperMC/Paper@d7510efc Fix #12722 (#12726)
PaperMC/Paper@0caf75f8 Fix #12721 (#12725)
PaperMC/Paper@bee28792 Adventure 4.23.0 (#12690)
PaperMC/Paper@692e93a9 Fix MC-299110
PaperMC/Paper@ea10fa4a Don't mutate the position of Items for MC-4 Fix (#12702)
PaperMC/Paper@aa6cd74c Remove unnecesary item check for ServerboundPlayerActionPacket RELEASE_USE_ITEM (#12668)
PaperMC/Paper@c9e89f49 Expose arrow velocity in EntityShootBowEvent for mobs (#12688)
PaperMC/Paper@7ec3174a Jump out of experimental phase
PaperMC/Paper@4e1a2555 Update try catch for command handling
PaperMC/Paper@e382e687 Fix 0 yield on explosion events
PaperMC/Paper@35b2c6ec Use dropped item for stats info (#12747)
PaperMC/Paper@bd79e20c [ci/skip] PluginManager#getPlugin and PluginManager#isPluginEnabled are case-insensitive (#12723)

Purpur Changes:
PurpurMC/Purpur@4a5974cf Updated Upstream (Paper)
PurpurMC/Purpur@3893bba0 this is important...
PurpurMC/Purpur@47e758fb Updated Upstream (Paper)

* Update PWT patch

* cleanup

* fix playermobcaps command

* fix Didn't fill chunk buffer in async chunk sending

* cleanup

* fix HurtByTargetGoal npe

* optimize collectSpawningChunks (#382)

* optimize collectSpawningChunks

* add bit set

* cleanup

* cleanup

* cleanup

* cleanup

* Updated Upstream (Paper/Purpur)

Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@57c202e0 Allow adventure nbt codec to parse all tags

Purpur Changes:
PurpurMC/Purpur@a4776d7b Updated Upstream (Paper)
PurpurMC/Purpur@dfd8a7ad Fix phantom going at high speed when ridden (#1680)

* Fix diff

---------

Signed-off-by: hayanesuru <hayanesuru@outlook.jp>
Co-authored-by: hayanesuru <hayanesuru@outlook.jp>
2025-06-30 05:17:33 +08:00

370 lines
30 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
Date: Tue, 9 Nov 2077 00:00:00 +0800
Subject: [PATCH] Faster random generator
This patch replaces LegacyRandomSource with FasterRandomSource by default,
which is faster in general.
Benchmark results (10,000,000 iterations) (Azul Zulu 23.0.1)
FasterRandomSource (Leaf) (Backed by Xoroshiro128PlusPlus): 51,633,700 ns
LegacyRandomSource (Vanilla): 254,857,500 ns
ThreadUnsafeRandom (Moonrise): 102,265,100 ns
SimpleThreadUnsafeRandom (Moonrise): 97,054,600 ns
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
index 91574985958950dffe0f393d7dfac4818af3b151..eaaa66c4d86d4ebda0acf8f1dbe8ecb55aa28285 100644
--- a/net/minecraft/server/level/ServerChunkCache.java
+++ b/net/minecraft/server/level/ServerChunkCache.java
@@ -154,7 +154,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
}
// Paper end - rewrite chunk system
// Paper start - chunk tick iteration optimisations
- private final ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom shuffleRandom = new ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom(0L);
+ private final net.minecraft.world.level.levelgen.BitRandomSource shuffleRandom = org.dreeam.leaf.config.modules.opt.FastRNG.enabled ? new org.dreeam.leaf.util.math.random.FasterRandomSource(0L) : new ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom(0L); // Leaf - Faster random generator
private void iterateTickingChunksFaster() {
final ServerLevel world = this.level;
final int randomTickSpeed = world.getGameRules().getInt(GameRules.RULE_RANDOMTICKING);
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
index d57a3a9b8ebd2f5d381336a0b5e81d71e2de6530..08d12a1acc3a672a77daa15f82392cd603c30283 100644
--- a/net/minecraft/server/level/ServerLevel.java
+++ b/net/minecraft/server/level/ServerLevel.java
@@ -895,7 +895,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
private void optimiseRandomTick(final LevelChunk chunk, final int tickSpeed) {
final LevelChunkSection[] sections = chunk.getSections();
final int minSection = ca.spottedleaf.moonrise.common.util.WorldUtil.getMinSection((ServerLevel)(Object)this);
- final ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom simpleRandom = this.simpleRandom;
+ final net.minecraft.world.level.levelgen.BitRandomSource simpleRandom = this.simpleRandom; // Leaf - Faster random generator - upcasting
final boolean doubleTickFluids = !ca.spottedleaf.moonrise.common.PlatformHooks.get().configFixMC224294();
final ChunkPos cpos = chunk.getPos();
@@ -944,7 +944,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
private int currentIceAndSnowTick = 0; protected void resetIceAndSnowTick() { this.currentIceAndSnowTick = this.simpleRandom.nextInt(16); } // Gale - Airplane - optimize random calls in chunk ticking
public void tickChunk(LevelChunk chunk, int randomTickSpeed) {
- final ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom simpleRandom = this.simpleRandom; // Paper - optimise random ticking
+ final net.minecraft.world.level.levelgen.BitRandomSource simpleRandom = this.simpleRandom; // Paper - optimise random ticking // Leaf - Faster random generator - upcasting
ChunkPos pos = chunk.getPos();
int minBlockX = pos.getMinBlockX();
int minBlockZ = pos.getMinBlockZ();
diff --git a/net/minecraft/util/RandomSource.java b/net/minecraft/util/RandomSource.java
index 8516d47b0ba79d91638837199e7ae0fb6cb44a79..4f4b55dd099dd2c2fea118b18b53588147e59bba 100644
--- a/net/minecraft/util/RandomSource.java
+++ b/net/minecraft/util/RandomSource.java
@@ -15,18 +15,40 @@ public interface RandomSource {
return create(RandomSupport.generateUniqueSeed());
}
+ // Leaf start - Faster random generator
@Deprecated
static RandomSource createThreadSafe() {
- return new ThreadSafeLegacyRandomSource(RandomSupport.generateUniqueSeed());
+ return org.dreeam.leaf.config.modules.opt.FastRNG.enabled
+ ? new org.dreeam.leaf.util.math.random.FasterRandomSource(RandomSupport.generateUniqueSeed())
+ : new ThreadSafeLegacyRandomSource(RandomSupport.generateUniqueSeed());
}
static RandomSource create(long seed) {
- return new LegacyRandomSource(seed);
+ return org.dreeam.leaf.config.modules.opt.FastRNG.enabled
+ ? new org.dreeam.leaf.util.math.random.FasterRandomSource(seed)
+ : new LegacyRandomSource(seed);
+ }
+
+ static RandomSource createForSlimeChunk(long seed) {
+ return org.dreeam.leaf.config.modules.opt.FastRNG.enabled && !org.dreeam.leaf.config.modules.opt.FastRNG.useLegacyForSlimeChunk
+ ? new org.dreeam.leaf.util.math.random.FasterRandomSource(seed)
+ : new LegacyRandomSource(seed);
}
static RandomSource createNewThreadLocalInstance() {
- return new SingleThreadedRandomSource(ThreadLocalRandom.current().nextLong());
+ return org.dreeam.leaf.config.modules.opt.FastRNG.enabled
+ ? new org.dreeam.leaf.util.math.random.FasterRandomSource(RandomSupport.generateUniqueSeed())
+ : new SingleThreadedRandomSource(ThreadLocalRandom.current().nextLong());
+ }
+
+ static RandomSource createLegacy() {
+ return new LegacyRandomSource(RandomSupport.generateUniqueSeed());
+ }
+
+ static RandomSource createLegacy(long seed) {
+ return new LegacyRandomSource(seed);
}
+ // Leaf end - Faster random generator
RandomSource fork();
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index 0cdd3eb97e74aa3955f014a1f8f6a7d1580d323f..574be7359a2ad62c95a42c46c7a0f3c7a42eb44e 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -155,7 +155,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
// Paper start - Share random for entities to make them more random
- public static RandomSource SHARED_RANDOM = new RandomRandomSource();
+ public static RandomSource SHARED_RANDOM = org.dreeam.leaf.config.modules.opt.FastRNG.enabled ? org.dreeam.leaf.util.math.random.FasterRandomSource.SHARED_INSTANCE : new RandomRandomSource(); // Leaf - Faster random generator
// Paper start - replace random
private static final class RandomRandomSource extends ca.spottedleaf.moonrise.common.util.ThreadUnsafeRandom {
public RandomRandomSource() {
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
index 3bd42eb81eae3af9323021a5dc6edaa06dfcaead..8ebfb2f5cf439190ea9bd4ad81d737fbcd4514c2 100644
--- a/net/minecraft/world/level/Level.java
+++ b/net/minecraft/world/level/Level.java
@@ -117,7 +117,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
public float rainLevel;
protected float oThunderLevel;
public float thunderLevel;
- public final RandomSource random = new ca.spottedleaf.moonrise.common.util.ThreadUnsafeRandom(net.minecraft.world.level.levelgen.RandomSupport.generateUniqueSeed()); // Paper - replace random
+ public final RandomSource random = org.dreeam.leaf.config.modules.opt.FastRNG.enabled ? new org.dreeam.leaf.util.math.random.FasterRandomSource(net.minecraft.world.level.levelgen.RandomSupport.generateUniqueSeed()) : new ca.spottedleaf.moonrise.common.util.ThreadUnsafeRandom(net.minecraft.world.level.levelgen.RandomSupport.generateUniqueSeed()); // Paper - replace random // Leaf - Faster random generator
@Deprecated
private final RandomSource threadSafeRandom = RandomSource.createThreadSafe();
private final Holder<DimensionType> dimensionTypeRegistration;
@@ -169,7 +169,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
private int tileTickPosition;
public final Map<ServerExplosion.CacheKey, Float> explosionDensityCache = new java.util.HashMap<>(); // Paper - Optimize explosions
public java.util.ArrayDeque<net.minecraft.world.level.block.RedstoneTorchBlock.Toggle> redstoneUpdateInfos; // Paper - Faster redstone torch rapid clock removal; Move from Map in BlockRedstoneTorch to here
- public final ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom simpleRandom = new ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom(net.minecraft.world.level.levelgen.RandomSupport.generateUniqueSeed()); // Gale - Pufferfish - move random tick random
+ public final net.minecraft.world.level.levelgen.BitRandomSource simpleRandom = org.dreeam.leaf.config.modules.opt.FastRNG.enabled ? new org.dreeam.leaf.util.math.random.FasterRandomSource(net.minecraft.world.level.levelgen.RandomSupport.generateUniqueSeed()) : new ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom(net.minecraft.world.level.levelgen.RandomSupport.generateUniqueSeed()); // Gale - Pufferfish - move random tick random // Leaf - Faster random generator
// Purpur start - Add adjustable breeding cooldown to config
private com.google.common.cache.Cache<BreedingCooldownPair, Object> playerBreedingCooldowns;
diff --git a/net/minecraft/world/level/biome/Biome.java b/net/minecraft/world/level/biome/Biome.java
index bad1a03167f7586e5279592adcb43350c9b528cd..336d42d4e85716843633030ba1aa21b7901ca601 100644
--- a/net/minecraft/world/level/biome/Biome.java
+++ b/net/minecraft/world/level/biome/Biome.java
@@ -55,14 +55,14 @@ public final class Biome {
);
public static final Codec<Holder<Biome>> CODEC = RegistryFileCodec.create(Registries.BIOME, DIRECT_CODEC);
public static final Codec<HolderSet<Biome>> LIST_CODEC = RegistryCodecs.homogeneousList(Registries.BIOME, DIRECT_CODEC);
- private static final PerlinSimplexNoise TEMPERATURE_NOISE = new PerlinSimplexNoise(new WorldgenRandom(new LegacyRandomSource(1234L)), ImmutableList.of(0));
+ private static final PerlinSimplexNoise TEMPERATURE_NOISE = new PerlinSimplexNoise(new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(1234L) : new LegacyRandomSource(1234L)), ImmutableList.of(0)); // Leaf - Faster random generator
static final PerlinSimplexNoise FROZEN_TEMPERATURE_NOISE = new PerlinSimplexNoise(
- new WorldgenRandom(new LegacyRandomSource(3456L)), ImmutableList.of(-2, -1, 0)
+ new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(3456L) : new LegacyRandomSource(3456L)), ImmutableList.of(-2, -1, 0) // Leaf - Faster random generator
);
@Deprecated(
forRemoval = true
)
- public static final PerlinSimplexNoise BIOME_INFO_NOISE = new PerlinSimplexNoise(new WorldgenRandom(new LegacyRandomSource(2345L)), ImmutableList.of(0));
+ public static final PerlinSimplexNoise BIOME_INFO_NOISE = new PerlinSimplexNoise(new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(2345L) : new LegacyRandomSource(2345L)), ImmutableList.of(0)); // Leaf - Faster random generator
private static final int TEMPERATURE_CACHE_SIZE = 1024;
public final Biome.ClimateSettings climateSettings;
private final BiomeGenerationSettings generationSettings;
diff --git a/net/minecraft/world/level/chunk/ChunkGenerator.java b/net/minecraft/world/level/chunk/ChunkGenerator.java
index 23806f5f0c6c4ec9a86a6ea13b89b4f57372e6f1..e1ebbfab87aed9cc633f2fedb1e6edeca4ddc2ec 100644
--- a/net/minecraft/world/level/chunk/ChunkGenerator.java
+++ b/net/minecraft/world/level/chunk/ChunkGenerator.java
@@ -455,7 +455,7 @@ public abstract class ChunkGenerator {
int x = chunk.getPos().x;
int z = chunk.getPos().z;
for (org.bukkit.generator.BlockPopulator populator : world.getPopulators()) {
- WorldgenRandom seededrandom = new WorldgenRandom(new net.minecraft.world.level.levelgen.LegacyRandomSource(level.getSeed()));
+ WorldgenRandom seededrandom = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(level.getSeed()) : new net.minecraft.world.level.levelgen.LegacyRandomSource(level.getSeed())); // Leaf - Faster random generator
seededrandom.setDecorationSeed(level.getSeed(), x, z);
populator.populate(world, new org.bukkit.craftbukkit.util.RandomSourceWrapper.RandomWrapper(seededrandom), x, z, limitedRegion);
}
@@ -560,7 +560,7 @@ public abstract class ChunkGenerator {
if (org.dreeam.leaf.config.modules.misc.SecureSeed.enabled) {
worldgenRandom = new su.plo.matter.WorldgenCryptoRandom(pos.x, pos.z, su.plo.matter.Globals.Salt.GENERATE_FEATURE, 0);
} else {
- worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
+ worldgenRandom = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(0L) : new LegacyRandomSource(0L)); // Leaf - Faster random generator
worldgenRandom.setLargeFeatureSeed(structureState.getLevelSeed(), pos.x, pos.z);
}
// Leaf end - Matter - Secure Seed
diff --git a/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java b/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java
index 426692d9627f46d708f551bd22ce3c52b2a23b37..8a19fd2b816b07a7374cb9dc96896a122f95db20 100644
--- a/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java
+++ b/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java
@@ -208,7 +208,7 @@ public class ChunkGeneratorStructureState {
// Leaf start - Matter - Secure Seed
RandomSource randomSource = org.dreeam.leaf.config.modules.misc.SecureSeed.enabled
? new su.plo.matter.WorldgenCryptoRandom(0, 0, su.plo.matter.Globals.Salt.STRONGHOLDS, 0)
- : RandomSource.create();
+ : RandomSource.createLegacy(); // Leaf - Faster random generator
// Leaf end - Matter - Secure Seed
if (!org.dreeam.leaf.config.modules.misc.SecureSeed.enabled) {
// Paper start - Add missing structure set seed configs
diff --git a/net/minecraft/world/level/levelgen/DensityFunctions.java b/net/minecraft/world/level/levelgen/DensityFunctions.java
index 77731406cb3dc417aa2fe1cb4352f3d2d7d498aa..1420dac658c4b27d25882a6d7dd3efb2c5b7e720 100644
--- a/net/minecraft/world/level/levelgen/DensityFunctions.java
+++ b/net/minecraft/world/level/levelgen/DensityFunctions.java
@@ -518,7 +518,7 @@ public final class DensityFunctions {
// Paper end - Perf: Optimize end generation
public EndIslandDensityFunction(long seed) {
- RandomSource randomSource = new LegacyRandomSource(seed);
+ RandomSource randomSource = org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(seed) : new LegacyRandomSource(seed); // Leaf - Faster random generator
randomSource.consumeCount(17292);
this.islandNoise = new SimplexNoise(randomSource);
}
diff --git a/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java b/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java
index 65728ef17e63d71833677fdcbd5bb90794b4822b..57ae4aaf1431021daf77c5638038d4910a358155 100644
--- a/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java
+++ b/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java
@@ -254,7 +254,7 @@ public final class NoiseBasedChunkGenerator extends ChunkGenerator {
WorldGenRegion level, long seed, RandomState random, BiomeManager biomeManager, StructureManager structureManager, ChunkAccess chunk
) {
BiomeManager biomeManager1 = biomeManager.withDifferentSource((x, y, z) -> this.biomeSource.getNoiseBiome(x, y, z, random.sampler()));
- WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(RandomSupport.generateUniqueSeed()));
+ WorldgenRandom worldgenRandom = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(RandomSupport.generateUniqueSeed()) : new LegacyRandomSource(RandomSupport.generateUniqueSeed())); // Leaf - Faster random generator
int i = 8;
ChunkPos pos = chunk.getPos();
NoiseChunk noiseChunk = chunk.getOrCreateNoiseChunk(chunkAccess -> this.createNoiseChunk(chunkAccess, structureManager, Blender.of(level), random));
@@ -420,7 +420,7 @@ public final class NoiseBasedChunkGenerator extends ChunkGenerator {
if (!this.settings.value().disableMobGeneration()) {
ChunkPos center = level.getCenter();
Holder<Biome> biome = level.getBiome(center.getWorldPosition().atY(level.getMaxY()));
- WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(RandomSupport.generateUniqueSeed()));
+ WorldgenRandom worldgenRandom = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(RandomSupport.generateUniqueSeed()) : new LegacyRandomSource(RandomSupport.generateUniqueSeed())); // Leaf - Faster random generator
worldgenRandom.setDecorationSeed(level.getSeed(), center.getMinBlockX(), center.getMinBlockZ());
NaturalSpawner.spawnMobsForChunkGeneration(level, biome, center, worldgenRandom);
}
diff --git a/net/minecraft/world/level/levelgen/WorldgenRandom.java b/net/minecraft/world/level/levelgen/WorldgenRandom.java
index c2d7cd788071e25b8ba2503c30ae80c7a9f353ed..a22508c50b34ca48328595cc7b69e008bf17d370 100644
--- a/net/minecraft/world/level/levelgen/WorldgenRandom.java
+++ b/net/minecraft/world/level/levelgen/WorldgenRandom.java
@@ -69,7 +69,7 @@ public class WorldgenRandom extends LegacyRandomSource {
}
public static RandomSource seedSlimeChunk(int chunkX, int chunkZ, long levelSeed, long salt) {
- return RandomSource.create(levelSeed + chunkX * chunkX * 4987142 + chunkX * 5947611 + chunkZ * chunkZ * 4392871L + chunkZ * 389711 ^ salt);
+ return RandomSource.createForSlimeChunk(levelSeed + chunkX * chunkX * 4987142 + chunkX * 5947611 + chunkZ * chunkZ * 4392871L + chunkZ * 389711 ^ salt); // Leaf - Faster random generator
}
public static enum Algorithm {
diff --git a/net/minecraft/world/level/levelgen/feature/GeodeFeature.java b/net/minecraft/world/level/levelgen/feature/GeodeFeature.java
index 8df6dadfeb2c282bc3c3f521d31f7277caa77790..e30dc383695727c31bee46f7dbaf82619bb8a6fa 100644
--- a/net/minecraft/world/level/levelgen/feature/GeodeFeature.java
+++ b/net/minecraft/world/level/levelgen/feature/GeodeFeature.java
@@ -44,7 +44,7 @@ public class GeodeFeature extends Feature<GeodeConfiguration> {
// Leaf start - Matter - Secure Seed
WorldgenRandom worldgenRandom = org.dreeam.leaf.config.modules.misc.SecureSeed.enabled
? new su.plo.matter.WorldgenCryptoRandom(0, 0, su.plo.matter.Globals.Salt.GEODE_FEATURE, 0)
- : new WorldgenRandom(new LegacyRandomSource(worldGenLevel.getSeed()));
+ : new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(worldGenLevel.getSeed()) : new LegacyRandomSource(worldGenLevel.getSeed())); // Leaf - Faster random generator
// Leaf end - Matter - Secure Seed
NormalNoise normalNoise = NormalNoise.create(worldgenRandom, -4, 1.0);
List<BlockPos> list1 = Lists.newLinkedList();
diff --git a/net/minecraft/world/level/levelgen/feature/stateproviders/DualNoiseProvider.java b/net/minecraft/world/level/levelgen/feature/stateproviders/DualNoiseProvider.java
index 48ab8a568d97052fe205e6a1f89862ee23d65abb..a190b5e890cf34dd1aa46cb9e283f05154fbe3e5 100644
--- a/net/minecraft/world/level/levelgen/feature/stateproviders/DualNoiseProvider.java
+++ b/net/minecraft/world/level/levelgen/feature/stateproviders/DualNoiseProvider.java
@@ -43,7 +43,7 @@ public class DualNoiseProvider extends NoiseProvider {
this.variety = variety;
this.slowNoiseParameters = slowNoiseParameters;
this.slowScale = slowScale;
- this.slowNoise = NormalNoise.create(new WorldgenRandom(new LegacyRandomSource(seed)), slowNoiseParameters);
+ this.slowNoise = NormalNoise.create(new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(seed) : new LegacyRandomSource(seed)), slowNoiseParameters); // Leaf - Faster random generator
}
@Override
diff --git a/net/minecraft/world/level/levelgen/feature/stateproviders/NoiseBasedStateProvider.java b/net/minecraft/world/level/levelgen/feature/stateproviders/NoiseBasedStateProvider.java
index f685372a39976f823202f2d9015c14f835b94a0c..bdd1b4ab758fc653df4adad7633ef430ebb89dbe 100644
--- a/net/minecraft/world/level/levelgen/feature/stateproviders/NoiseBasedStateProvider.java
+++ b/net/minecraft/world/level/levelgen/feature/stateproviders/NoiseBasedStateProvider.java
@@ -28,7 +28,7 @@ public abstract class NoiseBasedStateProvider extends BlockStateProvider {
this.seed = seed;
this.parameters = parameters;
this.scale = scale;
- this.noise = NormalNoise.create(new WorldgenRandom(new LegacyRandomSource(seed)), parameters);
+ this.noise = NormalNoise.create(new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(seed) : new LegacyRandomSource(seed)), parameters); // Leaf - Faster random generator
}
protected double getNoiseValue(BlockPos pos, double delta) {
diff --git a/net/minecraft/world/level/levelgen/structure/Structure.java b/net/minecraft/world/level/levelgen/structure/Structure.java
index 28281491be6b54de18c49ff0d52e302575d3ad38..3aa35d67df8f9118c944cebfcb675cccd9d99be2 100644
--- a/net/minecraft/world/level/levelgen/structure/Structure.java
+++ b/net/minecraft/world/level/levelgen/structure/Structure.java
@@ -254,7 +254,7 @@ public abstract class Structure {
return new su.plo.matter.WorldgenCryptoRandom(chunkPos.x, chunkPos.z, su.plo.matter.Globals.Salt.GENERATE_FEATURE, seed);
}
// Leaf end - Matter - Secure Seed
- WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
+ WorldgenRandom worldgenRandom = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(0L) : new LegacyRandomSource(0L)); // Leaf - Faster random generator
worldgenRandom.setLargeFeatureSeed(seed, chunkPos.x, chunkPos.z);
return worldgenRandom;
}
diff --git a/net/minecraft/world/level/levelgen/structure/placement/RandomSpreadStructurePlacement.java b/net/minecraft/world/level/levelgen/structure/placement/RandomSpreadStructurePlacement.java
index 6584c9320361dbbdea1899ab9e43b444de5006a6..06083cc7612ef28bcd9264bb21ab0bbbe0837589 100644
--- a/net/minecraft/world/level/levelgen/structure/placement/RandomSpreadStructurePlacement.java
+++ b/net/minecraft/world/level/levelgen/structure/placement/RandomSpreadStructurePlacement.java
@@ -72,7 +72,7 @@ public class RandomSpreadStructurePlacement extends StructurePlacement {
if (org.dreeam.leaf.config.modules.misc.SecureSeed.enabled) {
worldgenRandom = new su.plo.matter.WorldgenCryptoRandom(i, i1, su.plo.matter.Globals.Salt.POTENTIONAL_FEATURE, this.salt);
} else {
- worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
+ worldgenRandom = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(0L) : new LegacyRandomSource(0L)); // Leaf - Faster random generator
worldgenRandom.setLargeFeatureWithSalt(seed, i, i1, this.salt());
}
// Leaf end - Matter - Secure Seed
diff --git a/net/minecraft/world/level/levelgen/structure/placement/StructurePlacement.java b/net/minecraft/world/level/levelgen/structure/placement/StructurePlacement.java
index ee60717e39928a9f89ad6c7a9b3b52ac156871e6..daed7cc619d5a0b7d7a75e013cb72ed88d57de6c 100644
--- a/net/minecraft/world/level/levelgen/structure/placement/StructurePlacement.java
+++ b/net/minecraft/world/level/levelgen/structure/placement/StructurePlacement.java
@@ -124,7 +124,7 @@ public abstract class StructurePlacement {
if (org.dreeam.leaf.config.modules.misc.SecureSeed.enabled) {
worldgenRandom = new su.plo.matter.WorldgenCryptoRandom(regionX, regionZ, su.plo.matter.Globals.Salt.UNDEFINED, salt);
} else {
- worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
+ worldgenRandom = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(0L) : new LegacyRandomSource(0L)); // Leaf - Faster random generator
worldgenRandom.setLargeFeatureWithSalt(levelSeed, salt, regionX, regionZ);
}
// Leaf end - Matter - Secure Seed
@@ -133,7 +133,7 @@ public abstract class StructurePlacement {
}
private static boolean legacyProbabilityReducerWithDouble(long baseSeed, int salt, int chunkX, int chunkZ, float probability, @org.jetbrains.annotations.Nullable Integer saltOverride) { // Paper - Add missing structure set seed configs
- WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
+ WorldgenRandom worldgenRandom = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(0L) : new LegacyRandomSource(0L)); // Leaf - Faster random generator
if (saltOverride == null) { // Paper - Add missing structure set seed configs
worldgenRandom.setLargeFeatureSeed(baseSeed, chunkX, chunkZ);
// Paper start - Add missing structure set seed configs
@@ -145,7 +145,7 @@ public abstract class StructurePlacement {
}
private static boolean legacyArbitrarySaltProbabilityReducer(long levelSeed, int salt, int regionX, int regionZ, float probability, @org.jetbrains.annotations.Nullable Integer saltOverride) { // Paper - Add missing structure set seed configs
- WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
+ WorldgenRandom worldgenRandom = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(0L) : new LegacyRandomSource(0L)); // Leaf - Faster random generator
worldgenRandom.setLargeFeatureWithSalt(levelSeed, regionX, regionZ, saltOverride != null ? saltOverride : HIGHLY_ARBITRARY_RANDOM_SALT); // Paper - Add missing structure set seed configs
return worldgenRandom.nextFloat() < probability;
}
@@ -153,7 +153,7 @@ public abstract class StructurePlacement {
private static boolean legacyPillagerOutpostReducer(long levelSeed, int salt, int regionX, int regionZ, float probability, @org.jetbrains.annotations.Nullable Integer saltOverride) { // Paper - Add missing structure set seed configs; ignore here
int i = regionX >> 4;
int i1 = regionZ >> 4;
- WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
+ WorldgenRandom worldgenRandom = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(0L) : new LegacyRandomSource(0L)); // Leaf - Faster random generator
worldgenRandom.setSeed(i ^ i1 << 4 ^ levelSeed);
worldgenRandom.nextInt();
return worldgenRandom.nextInt((int)(1.0F / probability)) == 0;
diff --git a/net/minecraft/world/level/levelgen/structure/structures/OceanMonumentStructure.java b/net/minecraft/world/level/levelgen/structure/structures/OceanMonumentStructure.java
index 6941b2c89df8a7c77166e3fb76150cbc852371d9..661c26c4b981d504988c7498be45a5ddacaf90d8 100644
--- a/net/minecraft/world/level/levelgen/structure/structures/OceanMonumentStructure.java
+++ b/net/minecraft/world/level/levelgen/structure/structures/OceanMonumentStructure.java
@@ -56,7 +56,7 @@ public class OceanMonumentStructure extends Structure {
if (piecesContainer.isEmpty()) {
return piecesContainer;
} else {
- WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(RandomSupport.generateUniqueSeed()));
+ WorldgenRandom worldgenRandom = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(RandomSupport.generateUniqueSeed()) : new LegacyRandomSource(RandomSupport.generateUniqueSeed())); // Leaf - Faster random generator
worldgenRandom.setLargeFeatureSeed(seed, chunkPos.x, chunkPos.z);
StructurePiece structurePiece = piecesContainer.pieces().get(0);
BoundingBox boundingBox = structurePiece.getBoundingBox();
diff --git a/net/minecraft/world/level/levelgen/synth/PerlinSimplexNoise.java b/net/minecraft/world/level/levelgen/synth/PerlinSimplexNoise.java
index 434e72fd770a259d67e5e7f110f49b09bab6c54e..720098d50ecefeff25e8f032e33742ad6bd6ab21 100644
--- a/net/minecraft/world/level/levelgen/synth/PerlinSimplexNoise.java
+++ b/net/minecraft/world/level/levelgen/synth/PerlinSimplexNoise.java
@@ -43,7 +43,7 @@ public class PerlinSimplexNoise {
if (i1 > 0) {
long l = (long)(simplexNoise.getValue(simplexNoise.xo, simplexNoise.yo, simplexNoise.zo) * 9.223372E18F);
- RandomSource randomSource = new WorldgenRandom(new LegacyRandomSource(l));
+ RandomSource randomSource = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(l) : new LegacyRandomSource(l)); // Leaf - Faster random generator
for (int i5 = i3 - 1; i5 >= 0; i5--) {
if (i5 < i2 && octaves.contains(i3 - i5)) {