9
0
mirror of https://github.com/Dreeam-qwq/Gale.git synced 2025-12-21 15:59:28 +00:00
Files
Gale/patches/server/0101-Skip-unnecessary-mob-spawning-computations.patch
Dreeam a4ed88543a Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@681c013 Bundle spark (#11093)
PaperMC/Paper@5fee9c6 Move configuration option to a system property
PaperMC/Paper@aa3b356 Improve server startup logging (#11110)
PaperMC/Paper@9aea240 Properly lookup plugin classes when looked up by spark
PaperMC/Paper@7e91a2c Update the bundled spark version
2024-07-21 07:11:14 +08:00

80 lines
5.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Sun, 25 Dec 2022 20:29:03 +0100
Subject: [PATCH] Skip unnecessary mob spawning computations
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
This patch is based on the following patch:
"Only create a spawner state when we are actually spawning mobs"
By: PureGero <puregero@gmail.com>
As part of: MultiPaper (https://github.com/MultiPaper/MultiPaper)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index 406bd21684664db07cb0f541e619cc5f51070b7a..d2750fb7efbe8c1c77d4cb57f6ceec4fd968e326 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -441,11 +441,16 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
// Paper - chunk tick iteration optimisations
if (this.level.tickRateManager().runsNormally()) {
+ // Gale start - MultiPaper - skip unnecessary mob spawning computations
+ NaturalSpawner.SpawnState spawnercreature_d; // moved down
+ final boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !this.level.players().isEmpty(); // CraftBukkit
+ boolean flagAndHasNaturalSpawn = flag && this.anySpawnCategoryIsSpawnedThisTick();
+ if (flagAndHasNaturalSpawn) {
+ // Gale end - MultiPaper - skip unnecessary mob spawning computations
this.level.timings.countNaturalMobs.startTiming(); // Paper - timings
int k = this.distanceManager.getNaturalSpawnChunkCount();
// Paper start - Optional per player mob spawns
int naturalSpawnChunkCount = k;
- NaturalSpawner.SpawnState spawnercreature_d; // moved down
if ((this.spawnFriendlies || this.spawnEnemies) && this.level.paperConfig().entities.spawning.perPlayerMobSpawns) { // don't count mobs when animals and monsters are disabled
// re-set mob counts
for (ServerPlayer player : this.level.players) {
@@ -469,7 +474,11 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
this.level.timings.countNaturalMobs.stopTiming(); // Paper - timings
this.lastSpawnState = spawnercreature_d;
- boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !this.level.players().isEmpty(); // CraftBukkit
+ // Gale start - MultiPaper - skip unnecessary mob spawning computations
+ } else {
+ spawnercreature_d = null;
+ }
+ // Gale end - MultiPaper - skip unnecessary mob spawning computations
if (!this.level.paperConfig().entities.spawning.perPlayerMobSpawns) Util.shuffle(list, this.level.random); // Paper - per player mob spawns - do not need this when per-player is enabled
// Paper start - PlayerNaturallySpawnCreaturesEvent
@@ -492,7 +501,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
if (true && this.chunkMap.anyPlayerCloseEnoughForSpawning(chunkcoordintpair)) { // Paper - rewrite chunk system
chunk1.incrementInhabitedTime(j);
- if (flag && (this.spawnEnemies || this.spawnFriendlies) && this.level.getWorldBorder().isWithinBounds(chunkcoordintpair) && this.chunkMap.anyPlayerCloseEnoughForSpawning(chunkcoordintpair, true)) { // Spigot
+ if (flagAndHasNaturalSpawn && (this.spawnEnemies || this.spawnFriendlies) && this.level.getWorldBorder().isWithinBounds(chunkcoordintpair) && this.chunkMap.anyPlayerCloseEnoughForSpawning(chunkcoordintpair, true)) { // Spigot // Gale - MultiPaper - skip unnecessary mob spawning computations
NaturalSpawner.spawnForChunk(this.level, chunk1, spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag1);
}
@@ -535,6 +544,20 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
}
}
+ // Gale start - MultiPaper - skip unnecessary mob spawning computations
+ public boolean anySpawnCategoryIsSpawnedThisTick() {
+ long gameTime = this.level.getLevelData().getGameTime();
+
+ for (long ticksForSpawnCategory : this.level.ticksPerSpawnCategory.values()) {
+ if (ticksForSpawnCategory != 0L && gameTime % ticksForSpawnCategory == 0L) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+ // Gale end - MultiPaper - skip unnecessary mob spawning computations
+
private void getFullChunk(long pos, Consumer<LevelChunk> chunkConsumer) {
// Paper start - rewrite chunk system
final LevelChunk fullChunk = this.getChunkNow(ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkX(pos), ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkZ(pos));