mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-29 11:59:24 +00:00
116 lines
6.9 KiB
Diff
116 lines
6.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: hayanesuru <hayanesuru@outlook.jp>
|
|
Date: Wed, 4 Jun 2025 20:54:32 +0900
|
|
Subject: [PATCH] preload mob spawning position
|
|
|
|
|
|
diff --git a/net/minecraft/world/level/NaturalSpawner.java b/net/minecraft/world/level/NaturalSpawner.java
|
|
index a55abb08093847a8bfec446659f9af5fb1df2824..555983c7fa7b1f2d72ebbc148ca3dcb7cd217c56 100644
|
|
--- a/net/minecraft/world/level/NaturalSpawner.java
|
|
+++ b/net/minecraft/world/level/NaturalSpawner.java
|
|
@@ -243,12 +243,61 @@ public final class NaturalSpawner {
|
|
// Paper end - throttle failed spawn attempts
|
|
) {
|
|
// Paper end - Optional per player mob spawns
|
|
- BlockPos randomPosWithin = getRandomPosWithin(level, chunk);
|
|
- if (randomPosWithin.getY() >= level.getMinY() + 1) {
|
|
- return spawnCategoryForPosition(category, level, chunk, randomPosWithin, filter, callback, maxSpawns, trackEntity, false); // Paper - Optional per player mob spawns // Paper - throttle failed spawn attempts
|
|
- }
|
|
+ // Leaf start - preload mob spawning position
|
|
+ BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();
|
|
|
|
- return 0; // Paper - throttle failed spawn attempts
|
|
+ if (org.dreeam.leaf.config.modules.opt.PreloadNaturalMobSpawning.enabled) {
|
|
+ if (chunk.cacheSpawnPosIndex == 16 || chunk.cacheSpawnPosIndex == -1) {
|
|
+ if (chunk.cacheSpawnPos == null) {
|
|
+ chunk.cacheSpawnPos = new long[16];
|
|
+ }
|
|
+ // cache friendly
|
|
+ for (int i = 0; i < 16; i++) {
|
|
+ mutableRandomPosWithin(pos, level, chunk);
|
|
+ if (pos.getY() >= level.getMinY() + 1
|
|
+ && level.getWorldBorder().isWithinBounds(pos)
|
|
+ && !level.isOutsideBuildHeight(pos)) {
|
|
+ LevelChunk chunk1 = chunk.getPos().longKey == ChunkPos.asLong(pos)
|
|
+ ? chunk
|
|
+ : level.chunkSource.getChunkAtIfLoadedImmediately(pos.getX() >> 4, pos.getZ() >> 4);
|
|
+ if (chunk1 != null) {
|
|
+ BlockState bs = chunk1.getBlockStateFinal(pos.getX(), pos.getY(), pos.getZ());
|
|
+ if (bs != null && !bs.isRedstoneConductor(level, pos)) {
|
|
+ chunk.cacheSpawnPos[i] = BlockPos.asLong(pos.getX(), pos.getY(), pos.getZ());
|
|
+ continue;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ chunk.cacheSpawnPos[i] = -1;
|
|
+ }
|
|
+ chunk.cacheSpawnPosIndex = 0;
|
|
+ }
|
|
+ long cachePos = chunk.cacheSpawnPos[chunk.cacheSpawnPosIndex];
|
|
+ chunk.cacheSpawnPosIndex++;
|
|
+ if (cachePos == -1) {
|
|
+ return 0;
|
|
+ }
|
|
+ pos.set(cachePos);
|
|
+ } else {
|
|
+ mutableRandomPosWithin(pos, level, chunk);
|
|
+ if (pos.getY() < level.getMinY() + 1
|
|
+ || !level.getWorldBorder().isWithinBounds(pos)
|
|
+ || level.isOutsideBuildHeight(pos)) {
|
|
+ return 0;
|
|
+ }
|
|
+ LevelChunk chunk1 = chunk.getPos().longKey == ChunkPos.asLong(pos)
|
|
+ ? chunk
|
|
+ : level.chunkSource.getChunkAtIfLoadedImmediately(pos.getX() >> 4, pos.getZ() >> 4);
|
|
+ if (chunk1 == null) {
|
|
+ return 0;
|
|
+ }
|
|
+ BlockState bs = chunk1.getBlockStateFinal(pos.getX(), pos.getY(), pos.getZ());
|
|
+ if (bs == null || bs.isRedstoneConductor(level, pos)) {
|
|
+ return 0;
|
|
+ }
|
|
+ }
|
|
+ return spawnCategoryForPosition(category, level, chunk, pos, filter, callback, maxSpawns, trackEntity, false); // Paper - Optional per player mob spawns // Paper - throttle failed spawn attempts
|
|
+ // Leaf end - preload mob spawning position
|
|
}
|
|
|
|
@VisibleForDebug
|
|
@@ -270,7 +319,12 @@ public final class NaturalSpawner {
|
|
MobCategory category, ServerLevel level, ChunkAccess chunk, BlockPos pos, NaturalSpawner.SpawnPredicate filter, NaturalSpawner.AfterSpawnCallback callback, final int maxSpawns, final @Nullable Consumer<Entity> trackEntity
|
|
// Paper start - throttle failed spawn attempts
|
|
) {
|
|
- spawnCategoryForPosition(category, level, chunk, pos, filter, callback, maxSpawns, trackEntity, false);
|
|
+ // Leaf start - preload mob spawning position
|
|
+ BlockState blockState = level.getBlockStateIfLoadedAndInBounds(pos);
|
|
+ if (blockState != null && !blockState.isRedstoneConductor(chunk, pos)) {
|
|
+ spawnCategoryForPosition(category, level, chunk, pos, filter, callback, maxSpawns, trackEntity, false);
|
|
+ }
|
|
+ // Leaf end - preload mob spawning position
|
|
}
|
|
public static int spawnCategoryForPosition(
|
|
MobCategory category, ServerLevel level, ChunkAccess chunk, BlockPos pos, NaturalSpawner.SpawnPredicate filter, NaturalSpawner.AfterSpawnCallback callback, final int maxSpawns, final @Nullable Consumer<Entity> trackEntity, final boolean nothing
|
|
@@ -281,8 +335,8 @@ public final class NaturalSpawner {
|
|
ChunkGenerator generator = level.getChunkSource().getGenerator();
|
|
int y = pos.getY();
|
|
int i = 0; // Paper - throttle failed spawn attempts
|
|
- BlockState blockState = level.getBlockStateIfLoadedAndInBounds(pos); // Paper - don't load chunks for mob spawn
|
|
- if (blockState != null && !blockState.isRedstoneConductor(chunk, pos)) { // Paper - don't load chunks for mob spawn
|
|
+ //BlockState blockState = level.getBlockStateIfLoadedAndInBounds(pos); // Paper - don't load chunks for mob spawn // Leaf - preload mob spawning position
|
|
+ if (true /*blockState != null && !blockState.isRedstoneConductor(chunk, pos)*/) { // Paper - don't load chunks for mob spawn // Leaf - preload mob spawning position
|
|
BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
|
|
//int i = 0; // Paper - throttle failed spawn attempts - move up
|
|
|
|
diff --git a/net/minecraft/world/level/chunk/LevelChunk.java b/net/minecraft/world/level/chunk/LevelChunk.java
|
|
index 31f19dfe16e270b55f3b44754c97ed8d9fa422cf..b79eefb182b0a9e9f22ccb649c4659483228082c 100644
|
|
--- a/net/minecraft/world/level/chunk/LevelChunk.java
|
|
+++ b/net/minecraft/world/level/chunk/LevelChunk.java
|
|
@@ -107,6 +107,8 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
|
|
// Paper start - rewrite chunk system
|
|
private boolean postProcessingDone;
|
|
private ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder chunkAndHolder;
|
|
+ public long[] cacheSpawnPos = null; // Leaf - preload mob spawning position
|
|
+ public int cacheSpawnPosIndex = -1; // Leaf - preload mob spawning position
|
|
|
|
@Override
|
|
public final boolean moonrise$isPostProcessingDone() {
|