9
0
mirror of https://github.com/Dreeam-qwq/Gale.git synced 2025-12-22 08:19:31 +00:00
Files
Gale/patches/server/0114-Skip-unnecessary-mob-spawning-computations.patch
2024-04-28 08:17:49 -04:00

80 lines
4.9 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 b96ff2f3889a7bee948019810b6a835645ea12bc..94689992b4d159ab996e00ae20afa8fef0e84db2 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -497,11 +497,16 @@ public class ServerChunkCache extends ChunkSource {
this.level.resetIceAndSnowTick(); // Gale - Airplane - optimize random calls in chunk ticking - reset ice & snow tick random
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) {
@@ -525,7 +530,11 @@ public class ServerChunkCache extends ChunkSource {
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
// Paper start - optimise chunk tick iteration
ChunkMap playerChunkMap = this.chunkMap;
@@ -613,7 +622,7 @@ public class ServerChunkCache extends ChunkSource {
if (tick && chunk1.chunkStatus.isOrAfter(net.minecraft.server.level.FullChunkStatus.ENTITY_TICKING)) {
// Paper end - optimise chunk tick iteration
chunk1.incrementInhabitedTime(j);
- if (spawn && flag && (this.spawnEnemies || this.spawnFriendlies) && this.level.getWorldBorder().isWithinBounds(chunkcoordintpair)) { // Spigot // Paper - optimise chunk tick iteration
+ if (spawn && flagAndHasNaturalSpawn && (this.spawnEnemies || this.spawnFriendlies) && this.level.getWorldBorder().isWithinBounds(chunkcoordintpair)) { // Spigot // Paper - optimise chunk tick iteration // Gale - MultiPaper - skip unnecessary mob spawning computations
NaturalSpawner.spawnForChunk(this.level, chunk1, spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag1);
}
@@ -659,6 +668,20 @@ public class ServerChunkCache extends ChunkSource {
}
}
+ // 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) {
ChunkHolder playerchunk = this.getVisibleChunkIfPresent(pos);