aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSpottedleaf <[email protected]>2024-11-27 06:16:27 -0800
committerSpottedleaf <[email protected]>2024-11-27 06:16:27 -0800
commitafb5b13056ebbcdd3ae834c039046ecad4fa89eb (patch)
treec7450619b5c1c2d66c065ca0b842f93760d90c0b
parent7e789e8376b855e0c25fbbf23cf957daf24aa577 (diff)
downloadPaper-afb5b13056ebbcdd3ae834c039046ecad4fa89eb.tar.gz
Paper-afb5b13056ebbcdd3ae834c039046ecad4fa89eb.zip
Replace SimpleRandom with (Simple)ThreadUnsafeRandom
ThreadUnsafeRandom is a random implementation that is identical to LegacyRandomSource behaviourally, but without the thread checks. SimpleThreadUnsafeRandom is ThreadUnsafeRandom except with its nextInt(int) function replaced with a faster but more biased implementation when bound is very large. Additionally, replace Level/Entity randoms with ThreadUnsafeRandom. This avoids the expensive CAS logic at the expense of losing the thread check.
-rw-r--r--patches/server/0009-MC-Utils.patch179
-rw-r--r--patches/server/1038-Moonrise-optimisation-patches.patch189
-rw-r--r--patches/server/1043-Detail-more-information-in-watchdog-dumps.patch12
-rw-r--r--patches/server/1070-Configurable-Entity-Despawn-Time.patch8
4 files changed, 323 insertions, 65 deletions
diff --git a/patches/server/0009-MC-Utils.patch b/patches/server/0009-MC-Utils.patch
index 1912c615e2..e857714e6c 100644
--- a/patches/server/0009-MC-Utils.patch
+++ b/patches/server/0009-MC-Utils.patch
@@ -4037,36 +4037,41 @@ index 0000000000000000000000000000000000000000..559c959aff3c9deef867b9e425fba3e2
+ private MoonriseConstants() {}
+
+}
-diff --git a/src/main/java/ca/spottedleaf/moonrise/common/util/SimpleRandom.java b/src/main/java/ca/spottedleaf/moonrise/common/util/SimpleRandom.java
+diff --git a/src/main/java/ca/spottedleaf/moonrise/common/util/SimpleThreadUnsafeRandom.java b/src/main/java/ca/spottedleaf/moonrise/common/util/SimpleThreadUnsafeRandom.java
new file mode 100644
-index 0000000000000000000000000000000000000000..a9ff1c1a70faf4b7a64b265932f07a8b8f00c1ff
+index 0000000000000000000000000000000000000000..8d57b9c141fbe049aea248faa547dc97ba24cba5
--- /dev/null
-+++ b/src/main/java/ca/spottedleaf/moonrise/common/util/SimpleRandom.java
-@@ -0,0 +1,52 @@
++++ b/src/main/java/ca/spottedleaf/moonrise/common/util/SimpleThreadUnsafeRandom.java
+@@ -0,0 +1,105 @@
+package ca.spottedleaf.moonrise.common.util;
+
-+import net.minecraft.world.level.levelgen.LegacyRandomSource;
++import net.minecraft.util.Mth;
++import net.minecraft.util.RandomSource;
++import net.minecraft.world.level.levelgen.BitRandomSource;
++import net.minecraft.world.level.levelgen.MarsagliaPolarGaussian;
++import net.minecraft.world.level.levelgen.PositionalRandomFactory;
+
+/**
-+ * Avoid costly CAS of superclass
++ * Avoid costly CAS of superclass + division in nextInt
+ */
-+public final class SimpleRandom extends LegacyRandomSource {
++public final class SimpleThreadUnsafeRandom implements BitRandomSource {
+
+ private static final long MULTIPLIER = 25214903917L;
+ private static final long ADDEND = 11L;
+ private static final int BITS = 48;
-+ private static final long MASK = (1L << BITS) - 1;
++ private static final long MASK = (1L << BITS) - 1L;
+
+ private long value;
++ private final MarsagliaPolarGaussian gaussianSource = new MarsagliaPolarGaussian(this);
+
-+ public SimpleRandom(final long seed) {
-+ super(0L);
-+ this.value = seed;
++ public SimpleThreadUnsafeRandom(final long seed) {
++ this.setSeed(seed);
+ }
+
+ @Override
+ public void setSeed(final long seed) {
+ this.value = (seed ^ MULTIPLIER) & MASK;
++ this.gaussianSource.reset();
+ }
+
+ private long advanceSeed() {
@@ -4094,6 +4099,154 @@ index 0000000000000000000000000000000000000000..a9ff1c1a70faf4b7a64b265932f07a8b
+ final long value = this.advanceSeed() >>> (BITS - Integer.SIZE);
+ return (int)((value * (long)bound) >>> Integer.SIZE);
+ }
++
++ @Override
++ public double nextGaussian() {
++ return this.gaussianSource.nextGaussian();
++ }
++
++ @Override
++ public RandomSource fork() {
++ return new SimpleThreadUnsafeRandom(this.nextLong());
++ }
++
++ @Override
++ public PositionalRandomFactory forkPositional() {
++ return new SimpleRandomPositionalFactory(this.nextLong());
++ }
++
++ public static final class SimpleRandomPositionalFactory implements PositionalRandomFactory {
++
++ private final long seed;
++
++ public SimpleRandomPositionalFactory(final long seed) {
++ this.seed = seed;
++ }
++
++ public long getSeed() {
++ return this.seed;
++ }
++
++ @Override
++ public RandomSource fromHashOf(final String string) {
++ return new SimpleThreadUnsafeRandom((long)string.hashCode() ^ this.seed);
++ }
++
++ @Override
++ public RandomSource fromSeed(final long seed) {
++ return new SimpleThreadUnsafeRandom(seed);
++ }
++
++ @Override
++ public RandomSource at(final int x, final int y, final int z) {
++ return new SimpleThreadUnsafeRandom(Mth.getSeed(x, y, z) ^ this.seed);
++ }
++
++ @Override
++ public void parityConfigString(final StringBuilder stringBuilder) {
++ stringBuilder.append("SimpleRandomPositionalFactory{").append(this.seed).append('}');
++ }
++ }
++}
+diff --git a/src/main/java/ca/spottedleaf/moonrise/common/util/ThreadUnsafeRandom.java b/src/main/java/ca/spottedleaf/moonrise/common/util/ThreadUnsafeRandom.java
+new file mode 100644
+index 0000000000000000000000000000000000000000..12eb3add0931a4d77acdf6e875c42dda9c313dc3
+--- /dev/null
++++ b/src/main/java/ca/spottedleaf/moonrise/common/util/ThreadUnsafeRandom.java
+@@ -0,0 +1,94 @@
++package ca.spottedleaf.moonrise.common.util;
++
++import net.minecraft.util.Mth;
++import net.minecraft.util.RandomSource;
++import net.minecraft.world.level.levelgen.BitRandomSource;
++import net.minecraft.world.level.levelgen.MarsagliaPolarGaussian;
++import net.minecraft.world.level.levelgen.PositionalRandomFactory;
++
++/**
++ * Avoid costly CAS of superclass
++ */
++public final class ThreadUnsafeRandom implements BitRandomSource {
++
++ private static final long MULTIPLIER = 25214903917L;
++ private static final long ADDEND = 11L;
++ private static final int BITS = 48;
++ private static final long MASK = (1L << BITS) - 1L;
++
++ private long value;
++ private final MarsagliaPolarGaussian gaussianSource = new MarsagliaPolarGaussian(this);
++
++ public ThreadUnsafeRandom(final long seed) {
++ this.setSeed(seed);
++ }
++
++ @Override
++ public void setSeed(final long seed) {
++ this.value = (seed ^ MULTIPLIER) & MASK;
++ this.gaussianSource.reset();
++ }
++
++ private long advanceSeed() {
++ return this.value = ((this.value * MULTIPLIER) + ADDEND) & MASK;
++ }
++
++ @Override
++ public int next(final int bits) {
++ return (int)(this.advanceSeed() >>> (BITS - bits));
++ }
++
++ @Override
++ public int nextInt() {
++ final long seed = this.advanceSeed();
++ return (int)(seed >>> (BITS - Integer.SIZE));
++ }
++
++ @Override
++ public double nextGaussian() {
++ return this.gaussianSource.nextGaussian();
++ }
++
++ @Override
++ public RandomSource fork() {
++ return new ThreadUnsafeRandom(this.nextLong());
++ }
++
++ @Override
++ public PositionalRandomFactory forkPositional() {
++ return new ThreadUnsafeRandomPositionalFactory(this.nextLong());
++ }
++
++ public static final class ThreadUnsafeRandomPositionalFactory implements PositionalRandomFactory {
++
++ private final long seed;
++
++ public ThreadUnsafeRandomPositionalFactory(final long seed) {
++ this.seed = seed;
++ }
++
++ public long getSeed() {
++ return this.seed;
++ }
++
++ @Override
++ public RandomSource fromHashOf(final String string) {
++ return new ThreadUnsafeRandom((long)string.hashCode() ^ this.seed);
++ }
++
++ @Override
++ public RandomSource fromSeed(final long seed) {
++ return new ThreadUnsafeRandom(seed);
++ }
++
++ @Override
++ public RandomSource at(final int x, final int y, final int z) {
++ return new ThreadUnsafeRandom(Mth.getSeed(x, y, z) ^ this.seed);
++ }
++
++ @Override
++ public void parityConfigString(final StringBuilder stringBuilder) {
++ stringBuilder.append("ThreadUnsafeRandomPositionalFactory{").append(this.seed).append('}');
++ }
++ }
+}
diff --git a/src/main/java/ca/spottedleaf/moonrise/common/util/TickThread.java b/src/main/java/ca/spottedleaf/moonrise/common/util/TickThread.java
new file mode 100644
@@ -4542,7 +4695,7 @@ index 46cab7a8c7b87ab01b26074b04f5a02b3907cfc4..49019b4a9bc4e634d54a9b0acaf9229a
+ // Paper end
}
diff --git a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
-index f0d470d7770e119f734b9e72021c806d0ea8ecbd..c3fe4481dd35f80815716e48beeeb07b1f51e30b 100644
+index 0ea9eba1367858dfa5284524a8dd2f79daf6fc69..18b64c00fa73e233bf41f519db54a1d43c2a8b1f 100644
--- a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
+++ b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
@@ -217,7 +217,7 @@ public class GlobalConfiguration extends ConfigurationPart {
@@ -5553,7 +5706,7 @@ index f6a3606b972064c4ec78487374e6197c0c447e27..8978fa74ceae06bef6aad3b74d654498
public ServerLevel(MinecraftServer minecraftserver, Executor executor, LevelStorageSource.LevelStorageAccess convertable_conversionsession, PrimaryLevelData iworlddataserver, ResourceKey<Level> resourcekey, LevelStem worlddimension, ChunkProgressListener worldloadlistener, boolean flag, long i, List<CustomSpawner> list, boolean flag1, @Nullable RandomSequences randomsequences, org.bukkit.World.Environment env, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider) {
super(iworlddataserver, resourcekey, minecraftserver.registryAccess(), worlddimension.type(), false, flag, i, minecraftserver.getMaxChainedNeighborUpdates(), gen, biomeProvider, env, spigotConfig -> minecraftserver.paperConfigurations.createWorldConfig(io.papermc.paper.configuration.PaperConfigurations.createWorldContextMap(convertable_conversionsession.levelDirectory.path(), iworlddataserver.getLevelName(), resourcekey.location(), spigotConfig, minecraftserver.registryAccess(), iworlddataserver.getGameRules()))); // Paper - create paper world configs
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
-index fd97a0e54ad8487b0c6f242fcb626f0b76f88274..785c7e11f92610be58b624d252d1858658496af7 100644
+index 2819ee5726c759e524ba558155bcc516f1b70606..c60e7f27ea4060e455a18feb6f6a7919e80a8fc8 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -309,6 +309,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
diff --git a/patches/server/1038-Moonrise-optimisation-patches.patch b/patches/server/1038-Moonrise-optimisation-patches.patch
index e66596c063..d70d12cc2d 100644
--- a/patches/server/1038-Moonrise-optimisation-patches.patch
+++ b/patches/server/1038-Moonrise-optimisation-patches.patch
@@ -13,6 +13,7 @@ Currently includes:
- Block/Biome Palette read optimisations
- StateHolder (BlockState/FluidState) property access optimisations
- Basic Fluid property read optimisations
+ - Entity/Level random replacement
See https://github.com/Tuinity/Moonrise
@@ -364,6 +365,19 @@ index 49fe9eed5d5d08abd6e9778fe0d0545f35552435..fc029c8fb22a7c8eeb23bfc171812f6d
}
private ChunkSystem() {}
+diff --git a/src/main/java/ca/spottedleaf/moonrise/common/util/ThreadUnsafeRandom.java b/src/main/java/ca/spottedleaf/moonrise/common/util/ThreadUnsafeRandom.java
+index 12eb3add0931a4d77acdf6e875c42dda9c313dc3..5239993a681d6113eec99fa627b85508656ed7ac 100644
+--- a/src/main/java/ca/spottedleaf/moonrise/common/util/ThreadUnsafeRandom.java
++++ b/src/main/java/ca/spottedleaf/moonrise/common/util/ThreadUnsafeRandom.java
+@@ -9,7 +9,7 @@ import net.minecraft.world.level.levelgen.PositionalRandomFactory;
+ /**
+ * Avoid costly CAS of superclass
+ */
+-public final class ThreadUnsafeRandom implements BitRandomSource {
++public class ThreadUnsafeRandom implements BitRandomSource { // Paper - replace random
+
+ private static final long MULTIPLIER = 25214903917L;
+ private static final long ADDEND = 11L;
diff --git a/src/main/java/ca/spottedleaf/moonrise/paper/PaperHooks.java b/src/main/java/ca/spottedleaf/moonrise/paper/PaperHooks.java
index c8f2457ab3b28f2c3a6b500bcea40261669c24a4..ca8b6a926dfff3fdd6b04228809a4480366120b2 100644
--- a/src/main/java/ca/spottedleaf/moonrise/paper/PaperHooks.java
@@ -26285,7 +26299,7 @@ index 65206fdfa5b94eaca139e433b4865c16b16641f3..bf4463bcb5dc439ac5a3fa08dd60845a
}
}
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
-index 0a895055ec7f61d3cb52d303bbe3f89486a322e7..10a9406e96ab0ab2404c0e0a9bef08e86a6a12a2 100644
+index 0a895055ec7f61d3cb52d303bbe3f89486a322e7..56a109dc832c231bf8470f46e1ff37565e9fdd7a 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -52,7 +52,7 @@ import net.minecraft.world.level.storage.DimensionDataStorage;
@@ -26366,7 +26380,7 @@ index 0a895055ec7f61d3cb52d303bbe3f89486a322e7..10a9406e96ab0ab2404c0e0a9bef08e8
+ }
+ // Paper end - rewrite chunk system
+ // Paper start - chunk tick iteration optimisations
-+ private final ca.spottedleaf.moonrise.common.util.SimpleRandom shuffleRandom = new ca.spottedleaf.moonrise.common.util.SimpleRandom(0L);
++ private final ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom shuffleRandom = new ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom(0L);
+ private boolean isChunkNearPlayer(final ChunkMap chunkMap, final ChunkPos chunkPos, final LevelChunk levelChunk) {
+ final ca.spottedleaf.moonrise.patches.chunk_system.level.chunk.ChunkData chunkData = ((ca.spottedleaf.moonrise.patches.chunk_system.level.chunk.ChunkSystemChunkHolder)((ca.spottedleaf.moonrise.patches.chunk_system.level.chunk.ChunkSystemLevelChunk)levelChunk).moonrise$getChunkAndHolder().holder())
+ .moonrise$getRealChunkHolder().holderData;
@@ -26801,7 +26815,7 @@ index b2fd3e936559c8fcb8b02ae3ef63c4f3bd0edb08..5bbc7ceaafc163f12344e5d5d355ad2f
if (!list.equals(this.lastPassengers)) {
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
-index c5f3e4dff83a85a3a5f29534afd84d4a332b1d3e..85c58214c13208ed30f0ae4a2722f172184123ab 100644
+index c5f3e4dff83a85a3a5f29534afd84d4a332b1d3e..9928e14a5a42a2f0deba86e9dcb1f6f9f59412ef 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -185,7 +185,7 @@ import org.bukkit.event.weather.LightningStrikeEvent;
@@ -27232,12 +27246,12 @@ index c5f3e4dff83a85a3a5f29534afd84d4a332b1d3e..85c58214c13208ed30f0ae4a2722f172
}
+ // Paper start - optimise random ticking
-+ private final ca.spottedleaf.moonrise.common.util.SimpleRandom simpleRandom = new ca.spottedleaf.moonrise.common.util.SimpleRandom(0L);
++ private final ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom simpleRandom = new ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom(net.minecraft.world.level.levelgen.RandomSupport.generateUniqueSeed());
+
+ 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.SimpleRandom simpleRandom = this.simpleRandom;
++ final ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom simpleRandom = this.simpleRandom;
+ final boolean doubleTickFluids = !ca.spottedleaf.moonrise.common.PlatformHooks.get().configFixMC224294();
+
+ final ChunkPos cpos = chunk.getPos();
@@ -27284,7 +27298,7 @@ index c5f3e4dff83a85a3a5f29534afd84d4a332b1d3e..85c58214c13208ed30f0ae4a2722f172
+ // Paper end - optimise random ticking
+
public void tickChunk(LevelChunk chunk, int randomTickSpeed) {
-+ final ca.spottedleaf.moonrise.common.util.SimpleRandom simpleRandom = this.simpleRandom; // Paper - optimise random ticking
++ final ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom simpleRandom = this.simpleRandom; // Paper - optimise random ticking
ChunkPos chunkcoordintpair = chunk.getPos();
boolean flag = this.isRaining();
int j = chunkcoordintpair.getMinBlockX();
@@ -27566,7 +27580,7 @@ index c5f3e4dff83a85a3a5f29534afd84d4a332b1d3e..85c58214c13208ed30f0ae4a2722f172
return crashreportsystemdetails;
}
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
-index d80a03a72d150f9f496203dbce18ddf6d4cffee2..aba3a9f42a5fad867511ee69b385c00e9c496039 100644
+index f6e130aba66935f808dcfd7ef987131092ddfe4e..2b6c5b2387b67f25d8877849ccbfaaa77eab51d3 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -218,7 +218,7 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
@@ -28437,7 +28451,7 @@ index 50040c497a819cd1229042ab3cb057d34a32cacc..1f9c436a632e4f110be61cf76fcfc3b7
+ // Paper end - block counting
}
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
-index 5949cbccb569ab1d518508d200e69ad9d7d0ba9a..a9e1ae7ad0b81e7488cb07876b32d7ba0a170365 100644
+index 5949cbccb569ab1d518508d200e69ad9d7d0ba9a..b810f887e536af938f978ca2af068e6ae89b5e60 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -176,7 +176,7 @@ import org.bukkit.event.player.PlayerTeleportEvent;
@@ -28449,7 +28463,89 @@ index 5949cbccb569ab1d518508d200e69ad9d7d0ba9a..a9e1ae7ad0b81e7488cb07876b32d7ba
// CraftBukkit start
private static final int CURRENT_LEVEL = 2;
-@@ -461,6 +461,156 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
+@@ -187,7 +187,17 @@ 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();
+- private static final class RandomRandomSource extends java.util.Random implements net.minecraft.world.level.levelgen.BitRandomSource {
++ // Paper start - replace random
++ private static final class RandomRandomSource extends ca.spottedleaf.moonrise.common.util.ThreadUnsafeRandom {
++ public RandomRandomSource() {
++ this(net.minecraft.world.level.levelgen.RandomSupport.generateUniqueSeed());
++ }
++
++ public RandomRandomSource(long seed) {
++ super(seed);
++ }
++
++ // Paper end - replace random
+ private boolean locked = false;
+
+ @Override
+@@ -200,61 +210,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
+ }
+ }
+
+- @Override
+- public RandomSource fork() {
+- return new net.minecraft.world.level.levelgen.LegacyRandomSource(this.nextLong());
+- }
+-
+- @Override
+- public net.minecraft.world.level.levelgen.PositionalRandomFactory forkPositional() {
+- return new net.minecraft.world.level.levelgen.LegacyRandomSource.LegacyPositionalRandomFactory(this.nextLong());
+- }
+-
+- // these below are added to fix reobf issues that I don't wanna deal with right now
+- @Override
+- public int next(int bits) {
+- return super.next(bits);
+- }
+-
+- @Override
+- public int nextInt(int origin, int bound) {
+- return net.minecraft.world.level.levelgen.BitRandomSource.super.nextInt(origin, bound);
+- }
+-
+- @Override
+- public long nextLong() {
+- return net.minecraft.world.level.levelgen.BitRandomSource.super.nextLong();
+- }
+-
+- @Override
+- public int nextInt() {
+- return net.minecraft.world.level.levelgen.BitRandomSource.super.nextInt();
+- }
+-
+- @Override
+- public int nextInt(int bound) {
+- return net.minecraft.world.level.levelgen.BitRandomSource.super.nextInt(bound);
+- }
+-
+- @Override
+- public boolean nextBoolean() {
+- return net.minecraft.world.level.levelgen.BitRandomSource.super.nextBoolean();
+- }
+-
+- @Override
+- public float nextFloat() {
+- return net.minecraft.world.level.levelgen.BitRandomSource.super.nextFloat();
+- }
+-
+- @Override
+- public double nextDouble() {
+- return net.minecraft.world.level.levelgen.BitRandomSource.super.nextDouble();
+- }
+-
+- @Override
+- public double nextGaussian() {
+- return super.nextGaussian();
+- }
++ // Paper - replace random
+ }
+ // Paper end - Share random for entities to make them more random
+ public org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason; // Paper - Entity#getEntitySpawnReason
+@@ -461,6 +417,156 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return this.dimensions.makeBoundingBox(x, y, z);
}
// Paper end
@@ -28606,7 +28702,7 @@ index 5949cbccb569ab1d518508d200e69ad9d7d0ba9a..a9e1ae7ad0b81e7488cb07876b32d7ba
public Entity(EntityType<?> type, Level world) {
this.id = Entity.ENTITY_COUNTER.incrementAndGet();
-@@ -1366,41 +1516,76 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
+@@ -1366,41 +1472,76 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
private Vec3 collide(Vec3 movement) {
@@ -28632,22 +28728,17 @@ index 5949cbccb569ab1d518508d200e69ad9d7d0ba9a..a9e1ae7ad0b81e7488cb07876b32d7ba
+ if (xZero & yZero & zZero) {
+ return movement;
+ }
++
++ final AABB currentBox = this.getBoundingBox();
++
++ final List<VoxelShape> potentialCollisionsVoxel = new ArrayList<>();
++ final List<AABB> potentialCollisionsBB = new ArrayList<>();
- List<VoxelShape> list1 = Entity.collectColliders(this, this.level, list, axisalignedbb2);
- float f = (float) vec3d1.y;
- float[] afloat = Entity.collectCandidateStepUpHeights(axisalignedbb1, list1, this.maxUpStep(), f);
- float[] afloat1 = afloat;
- int i = afloat.length;
-+ final AABB currentBox = this.getBoundingBox();
-
-- for (int j = 0; j < i; ++j) {
-- float f1 = afloat1[j];
-- Vec3 vec3d2 = Entity.collideWithShapes(new Vec3(movement.x, (double) f1, movement.z), axisalignedbb1, list1);
-+ final List<VoxelShape> potentialCollisionsVoxel = new ArrayList<>();
-+ final List<AABB> potentialCollisionsBB = new ArrayList<>();
-
-- if (vec3d2.horizontalDistanceSqr() > vec3d1.horizontalDistanceSqr()) {
-- double d0 = axisalignedbb.minY - axisalignedbb1.minY;
+ final AABB initialCollisionBox;
+ if (xZero & zZero) {
+ // note: xZero & zZero -> collision on x/z == 0 -> no step height calculation
@@ -28658,20 +28749,25 @@ index 5949cbccb569ab1d518508d200e69ad9d7d0ba9a..a9e1ae7ad0b81e7488cb07876b32d7ba
+ initialCollisionBox = currentBox.expandTowards(movement);
+ }
-- return vec3d2.add(0.0D, -d0, 0.0D);
-- }
+- for (int j = 0; j < i; ++j) {
+- float f1 = afloat1[j];
+- Vec3 vec3d2 = Entity.collideWithShapes(new Vec3(movement.x, (double) f1, movement.z), axisalignedbb1, list1);
+ final List<AABB> entityAABBs = new ArrayList<>();
+ ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.getEntityHardCollisions(
+ this.level, (Entity)(Object)this, initialCollisionBox, entityAABBs, 0, null
+ );
-+
+
+- if (vec3d2.horizontalDistanceSqr() > vec3d1.horizontalDistanceSqr()) {
+- double d0 = axisalignedbb.minY - axisalignedbb1.minY;
+ ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.getCollisionsForBlocksOrWorldBorder(
+ this.level, (Entity)(Object)this, initialCollisionBox, potentialCollisionsVoxel, potentialCollisionsBB,
+ ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.COLLISION_FLAG_CHECK_BORDER, null
+ );
+ potentialCollisionsBB.addAll(entityAABBs);
+ final Vec3 collided = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.performCollisions(movement, currentBox, potentialCollisionsVoxel, potentialCollisionsBB);
-+
+
+- return vec3d2.add(0.0D, -d0, 0.0D);
+- }
+ final boolean collidedX = collided.x != movement.x;
+ final boolean collidedY = collided.y != movement.y;
+ final boolean collidedZ = collided.z != movement.z;
@@ -28711,7 +28807,7 @@ index 5949cbccb569ab1d518508d200e69ad9d7d0ba9a..a9e1ae7ad0b81e7488cb07876b32d7ba
}
private static float[] collectCandidateStepUpHeights(AABB collisionBox, List<VoxelShape> collisions, float f, float stepHeight) {
-@@ -2788,18 +2973,110 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
+@@ -2788,18 +2929,110 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
public boolean isInWall() {
@@ -28829,7 +28925,7 @@ index 5949cbccb569ab1d518508d200e69ad9d7d0ba9a..a9e1ae7ad0b81e7488cb07876b32d7ba
}
public InteractionResult interact(Player player, InteractionHand hand) {
-@@ -4272,14 +4549,17 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
+@@ -4272,14 +4505,17 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
public Iterable<Entity> getIndirectPassengers() {
@@ -28854,7 +28950,7 @@ index 5949cbccb569ab1d518508d200e69ad9d7d0ba9a..a9e1ae7ad0b81e7488cb07876b32d7ba
}
private Iterable<Entity> getIndirectPassengers_old() {
// Paper end - Optimize indirect passenger iteration
-@@ -4437,82 +4717,136 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
+@@ -4437,82 +4673,136 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return Mth.lerp(delta, this.yRotO, this.yRot);
}
@@ -28955,7 +29051,9 @@ index 5949cbccb569ab1d518508d200e69ad9d7d0ba9a..a9e1ae7ad0b81e7488cb07876b32d7ba
+ final int maxZIterate = currChunkZ == maxChunkZ ? (maxBlockZ & 15) : 15;
+ final int minYIterate = currChunkY == minChunkY ? (minBlockY & 15) : 0;
+ final int maxYIterate = currChunkY == maxChunkY ? (maxBlockY & 15) : 15;
-+
+
+- vec3d = vec3d.add(vec3d1);
+- ++k1;
+ for (int currY = minYIterate; currY <= maxYIterate; ++currY) {
+ for (int currZ = minZIterate; currZ <= maxZIterate; ++currZ) {
+ for (int currX = minXIterate; currX <= maxXIterate; ++currX) {
@@ -28963,21 +29061,19 @@ index 5949cbccb569ab1d518508d200e69ad9d7d0ba9a..a9e1ae7ad0b81e7488cb07876b32d7ba
+
+ if (fluidState.isEmpty() || !fluidState.is(fluid)) {
+ continue;
-+ }
+ }
+- // CraftBukkit start - store last lava contact location
+- if (tag == FluidTags.LAVA) {
+- this.lastLavaContact = blockposition_mutableblockposition.immutable();
+
+ mutablePos.set(currX | (currChunkX << 4), currY | (currChunkY << 4), currZ | (currChunkZ << 4));
-
-- vec3d = vec3d.add(vec3d1);
-- ++k1;
++
+ final double height = (double)((float)mutablePos.getY() + fluidState.getHeight(world, mutablePos));
+ final double diff = height - boundingBox.minY;
+
+ if (diff < 0.0) {
+ continue;
- }
-- // CraftBukkit start - store last lava contact location
-- if (tag == FluidTags.LAVA) {
-- this.lastLavaContact = blockposition_mutableblockposition.immutable();
++ }
+
+ inFluid = true;
+ maxHeightDiff = Math.max(maxHeightDiff, diff);
@@ -29049,7 +29145,7 @@ index 5949cbccb569ab1d518508d200e69ad9d7d0ba9a..a9e1ae7ad0b81e7488cb07876b32d7ba
public boolean touchingUnloadedChunk() {
AABB axisalignedbb = this.getBoundingBox().inflate(1.0D);
-@@ -4664,6 +4998,15 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
+@@ -4664,6 +4954,15 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
this.setPosRaw(x, y, z, false);
}
public final void setPosRaw(double x, double y, double z, boolean forceBoundingBoxUpdate) {
@@ -29065,7 +29161,7 @@ index 5949cbccb569ab1d518508d200e69ad9d7d0ba9a..a9e1ae7ad0b81e7488cb07876b32d7ba
if (!checkPosition(this, x, y, z)) {
return;
}
-@@ -4793,6 +5136,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
+@@ -4793,6 +5092,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@Override
public final void setRemoved(Entity.RemovalReason entity_removalreason, EntityRemoveEvent.Cause cause) {
@@ -29078,7 +29174,7 @@ index 5949cbccb569ab1d518508d200e69ad9d7d0ba9a..a9e1ae7ad0b81e7488cb07876b32d7ba
CraftEventFactory.callEntityRemoveEvent(this, cause);
// CraftBukkit end
final boolean alreadyRemoved = this.removalReason != null; // Paper - Folia schedulers
-@@ -4804,7 +5153,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
+@@ -4804,7 +5109,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
this.stopRiding();
}
@@ -29087,7 +29183,7 @@ index 5949cbccb569ab1d518508d200e69ad9d7d0ba9a..a9e1ae7ad0b81e7488cb07876b32d7ba
this.levelCallback.onRemove(entity_removalreason);
this.onRemoval(entity_removalreason);
// Paper start - Folia schedulers
-@@ -4836,7 +5185,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
+@@ -4836,7 +5141,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@Override
public boolean shouldBeSaved() {
@@ -29486,7 +29582,7 @@ index e185a33b5b1f8e8e0a0e666b24ba3e9186a8a7ff..5d7a6e4b73f032db356e7ec369b15001
// Paper start - Affects Spawning API
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
-index 078088a854d466e66411d25d6dd6bcc536db78f3..86cd6e1b8f68dd0564ee2a7c60f02d7af287af67 100644
+index 078088a854d466e66411d25d6dd6bcc536db78f3..061d3e77fe8d9322eb660ac1995e025aba51ae1a 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -83,6 +83,7 @@ import net.minecraft.world.level.storage.LevelData;
@@ -29506,6 +29602,15 @@ index 078088a854d466e66411d25d6dd6bcc536db78f3..86cd6e1b8f68dd0564ee2a7c60f02d7a
public static final Codec<ResourceKey<Level>> RESOURCE_KEY_CODEC = ResourceKey.codec(Registries.DIMENSION);
public static final ResourceKey<Level> OVERWORLD = ResourceKey.create(Registries.DIMENSION, ResourceLocation.withDefaultNamespace("overworld"));
+@@ -130,7 +131,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
+ public float rainLevel;
+ protected float oThunderLevel;
+ public float thunderLevel;
+- public final RandomSource random = RandomSource.create();
++ public final RandomSource random = new ca.spottedleaf.moonrise.common.util.ThreadUnsafeRandom(net.minecraft.world.level.levelgen.RandomSupport.generateUniqueSeed()); // Paper - replace random
+ /** @deprecated */
+ @Deprecated
+ private final RandomSource threadSafeRandom = RandomSource.createThreadSafe();
@@ -206,7 +207,639 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
public abstract ResourceKey<LevelStem> getTypeKey();
@@ -36160,7 +36265,7 @@ index 4a5a0e33af16369f665bf39e70238e4e5a5486da..696152286a4d16fa51a23ff6e15fb297
// Paper start - implement pointers
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
-index 4459d9f205222764affae053930c15f5107d4e69..73de1c68e92bf6b17cbb5cd49447bc98ae0fb650 100644
+index 5989a9af8840e1bdb5c7a25a44473e2ab597e1e5..e1f20b5b9ebc5d9870136aa2c77d887094bd4b6e 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -3513,7 +3513,9 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
diff --git a/patches/server/1043-Detail-more-information-in-watchdog-dumps.patch b/patches/server/1043-Detail-more-information-in-watchdog-dumps.patch
index ded78aa33e..98c659d4a2 100644
--- a/patches/server/1043-Detail-more-information-in-watchdog-dumps.patch
+++ b/patches/server/1043-Detail-more-information-in-watchdog-dumps.patch
@@ -78,7 +78,7 @@ index f7197f1347251a37dd0f6d9ffa2f09bc3a4e1233..1f7f68aad97ee73763c042837f239bdc
});
throw RunningOnDifferentThreadException.RUNNING_ON_DIFFERENT_THREAD;
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
-index 85c58214c13208ed30f0ae4a2722f172184123ab..ff79925649ac1ceb6121c4b74fdb65f5f138f689 100644
+index 9928e14a5a42a2f0deba86e9dcb1f6f9f59412ef..d81be1069ef6ce51789df38ce21f125b6d524945 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -1253,7 +1253,26 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@@ -123,10 +123,10 @@ index 85c58214c13208ed30f0ae4a2722f172184123ab..ff79925649ac1ceb6121c4b74fdb65f5
private void tickPassenger(Entity vehicle, Entity passenger, boolean isActive) { // Paper - EAR 2
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
-index a9e1ae7ad0b81e7488cb07876b32d7ba0a170365..8be1b051543cda2b2e9e3d337834757e53f442de 100644
+index b810f887e536af938f978ca2af068e6ae89b5e60..8c62d1aa5c8a062685474dca7e91bf9f8b004ca5 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
-@@ -1172,8 +1172,43 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
+@@ -1128,8 +1128,43 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return this.onGround;
}
@@ -170,7 +170,7 @@ index a9e1ae7ad0b81e7488cb07876b32d7ba0a170365..8be1b051543cda2b2e9e3d337834757e
if (this.noPhysics) {
this.setPos(this.getX() + movement.x, this.getY() + movement.y, this.getZ() + movement.z);
} else {
-@@ -1294,6 +1329,13 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
+@@ -1250,6 +1285,13 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
gameprofilerfiller.pop();
}
}
@@ -184,7 +184,7 @@ index a9e1ae7ad0b81e7488cb07876b32d7ba0a170365..8be1b051543cda2b2e9e3d337834757e
}
private void applyMovementEmissionAndPlaySound(Entity.MovementEmission moveEffect, Vec3 movement, BlockPos landingPos, BlockState landingState) {
-@@ -4916,7 +4958,9 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
+@@ -4872,7 +4914,9 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
public void setDeltaMovement(Vec3 velocity) {
@@ -194,7 +194,7 @@ index a9e1ae7ad0b81e7488cb07876b32d7ba0a170365..8be1b051543cda2b2e9e3d337834757e
}
public void addDeltaMovement(Vec3 velocity) {
-@@ -5022,7 +5066,9 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
+@@ -4978,7 +5022,9 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
// Paper end - Fix MC-4
if (this.position.x != x || this.position.y != y || this.position.z != z) {
diff --git a/patches/server/1070-Configurable-Entity-Despawn-Time.patch b/patches/server/1070-Configurable-Entity-Despawn-Time.patch
index 9f3d4aa488..3885f857a3 100644
--- a/patches/server/1070-Configurable-Entity-Despawn-Time.patch
+++ b/patches/server/1070-Configurable-Entity-Despawn-Time.patch
@@ -5,10 +5,10 @@ Subject: [PATCH] Configurable Entity Despawn Time
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
-index 8be1b051543cda2b2e9e3d337834757e53f442de..ed5b00620527c1776722d25b1b45f1544802a341 100644
+index 8c62d1aa5c8a062685474dca7e91bf9f8b004ca5..a15546e433ebba6c0de01bdaaef201a3d99a87b5 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
-@@ -432,6 +432,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
+@@ -388,6 +388,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
private UUID originWorld;
public boolean freezeLocked = false; // Paper - Freeze Tick Lock API
public boolean fixedPose = false; // Paper - Expand Pose API
@@ -16,7 +16,7 @@ index 8be1b051543cda2b2e9e3d337834757e53f442de..ed5b00620527c1776722d25b1b45f154
public void setOrigin(@javax.annotation.Nonnull Location location) {
this.origin = location.toVector();
-@@ -614,6 +615,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
+@@ -570,6 +571,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
public Entity(EntityType<?> type, Level world) {
this.id = Entity.ENTITY_COUNTER.incrementAndGet();
@@ -24,7 +24,7 @@ index 8be1b051543cda2b2e9e3d337834757e53f442de..ed5b00620527c1776722d25b1b45f154
this.passengers = ImmutableList.of();
this.deltaMovement = Vec3.ZERO;
this.bb = Entity.INITIAL_AABB;
-@@ -912,6 +914,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
+@@ -868,6 +870,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
public void tick() {