Skip to content

Commit

Permalink
Add back IceAndSnowTick optimization in Optimize random calls in chun…
Browse files Browse the repository at this point in the history
…k ticking
  • Loading branch information
Dreeam-qwq committed Aug 6, 2024
1 parent 3b27166 commit 1acfc2a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
33 changes: 31 additions & 2 deletions patches/server/0017-Optimize-random-calls-in-chunk-ticking.patch
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,31 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index 3b3684d202e460a80b3e6e97afbaa4c84c4e3b3b..39b187dc90f79dbfff55be697b8cb4d404b290fc 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -441,6 +441,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon

// Paper - chunk tick iteration optimisations

+ this.level.resetIceAndSnowTick(); // Gale - Airplane - optimize random calls in chunk ticking - reset ice & snow tick random
if (this.level.tickRateManager().runsNormally()) {
this.level.timings.countNaturalMobs.startTiming(); // Paper - timings
int k = this.distanceManager.getNaturalSpawnChunkCount();
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 7aa13de4b3778e6708ed46ddcedde100f585a40f..2df8f9f7c631f7c4a67cfcaf218de1d29448d489 100644
index 7aa13de4b3778e6708ed46ddcedde100f585a40f..bad5725292cf549d2cd4f62bc3c77c321df24294 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -840,7 +840,7 @@ public class ServerLevel extends Level implements WorldGenLevel, ca.spottedleaf.
@@ -834,13 +834,15 @@ public class ServerLevel extends Level implements WorldGenLevel, ca.spottedleaf.
}
// Paper end - optimise random ticking

+ private int currentIceAndSnowTick = 0; protected void resetIceAndSnowTick() { this.currentIceAndSnowTick = this.random.nextInt(16); } // Gale - Airplane - optimize random calls in chunk ticking
+
public void tickChunk(LevelChunk chunk, int randomTickSpeed) {
ChunkPos chunkcoordintpair = chunk.getPos();
boolean flag = this.isRaining();
int j = chunkcoordintpair.getMinBlockX();
int k = chunkcoordintpair.getMinBlockZ();

Expand All @@ -64,6 +84,15 @@ index 7aa13de4b3778e6708ed46ddcedde100f585a40f..2df8f9f7c631f7c4a67cfcaf218de1d2
BlockPos blockposition = this.findLightningTargetAround(this.getBlockRandomPos(j, 0, k, 15));

if (this.isRainingAt(blockposition)) {
@@ -868,7 +870,7 @@ public class ServerLevel extends Level implements WorldGenLevel, ca.spottedleaf.
}
}

- if (!this.paperConfig().environment.disableIceAndSnow) { // Paper - Option to disable ice and snow
+ if (!this.paperConfig().environment.disableIceAndSnow && (this.currentIceAndSnowTick++ & 15) == 0) { // Paper - Option to disable ice and snow // Gale - Airplane - optimize random calls in chunk ticking - optimize further random ticking
for (int l = 0; l < randomTickSpeed; ++l) {
if (this.random.nextInt(48) == 0) {
this.tickPrecipitation(this.getBlockRandomPos(j, 0, k, 15));
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
index 36540053590c30a902b9986dcf2e74375157822d..f23ed06a943646f45e1291f35ab3025e1dfa6b49 100644
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ As part of: SportPaper (https://github.com/Electroid/SportPaper)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)

diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index bfefe93b1ab4facd4874210609ecbe244a4cff0d..0bc8711b91d81f37e65be17c3895a0dcfbe4f94e 100644
index 94bf091124aae1f0d318051076953be20c71cab2..8353c264597de5b1ddcc1643c87f6ea09a22523b 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -1576,7 +1576,17 @@ public class ServerLevel extends Level implements WorldGenLevel, ca.spottedleaf.
@@ -1578,7 +1578,17 @@ public class ServerLevel extends Level implements WorldGenLevel, ca.spottedleaf.

@Override
public void destroyBlockProgress(int entityId, BlockPos pos, int progress) {
Expand All @@ -35,7 +35,7 @@ index bfefe93b1ab4facd4874210609ecbe244a4cff0d..0bc8711b91d81f37e65be17c3895a0dc

// CraftBukkit start
Player entityhuman = null;
@@ -1610,7 +1620,7 @@ public class ServerLevel extends Level implements WorldGenLevel, ca.spottedleaf.
@@ -1612,7 +1622,7 @@ public class ServerLevel extends Level implements WorldGenLevel, ca.spottedleaf.
// CraftBukkit end

if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ 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 3b3684d202e460a80b3e6e97afbaa4c84c4e3b3b..9fd7b17b7806636777de40abb9963ce770a97d15 100644
index 39b187dc90f79dbfff55be697b8cb4d404b290fc..c520d824630e8b5c569c3213d019b2548120a50f 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -442,11 +442,16 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
// Paper - chunk tick iteration optimisations
@@ -443,11 +443,16 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon

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
Expand All @@ -34,7 +34,7 @@ index 3b3684d202e460a80b3e6e97afbaa4c84c4e3b3b..9fd7b17b7806636777de40abb9963ce7
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) {
@@ -470,7 +475,11 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
@@ -471,7 +476,11 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
this.level.timings.countNaturalMobs.stopTiming(); // Paper - timings

this.lastSpawnState = spawnercreature_d;
Expand All @@ -47,7 +47,7 @@ index 3b3684d202e460a80b3e6e97afbaa4c84c4e3b3b..9fd7b17b7806636777de40abb9963ce7

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
@@ -493,7 +502,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
@@ -494,7 +503,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon

if (true && this.chunkMap.anyPlayerCloseEnoughForSpawning(chunkcoordintpair)) { // Paper - rewrite chunk system
chunk1.incrementInhabitedTime(j);
Expand All @@ -56,7 +56,7 @@ index 3b3684d202e460a80b3e6e97afbaa4c84c4e3b3b..9fd7b17b7806636777de40abb9963ce7
NaturalSpawner.spawnForChunk(this.level, chunk1, spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag1);
}

@@ -536,6 +545,20 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
@@ -537,6 +546,20 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
}
}

Expand Down

0 comments on commit 1acfc2a

Please sign in to comment.