diff options
Diffstat (limited to 'patches/unapplied/server/1054-Improve-cancelling-PreCreatureSpawnEvent-with-per-pl.patch')
-rw-r--r-- | patches/unapplied/server/1054-Improve-cancelling-PreCreatureSpawnEvent-with-per-pl.patch | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/patches/unapplied/server/1054-Improve-cancelling-PreCreatureSpawnEvent-with-per-pl.patch b/patches/unapplied/server/1054-Improve-cancelling-PreCreatureSpawnEvent-with-per-pl.patch new file mode 100644 index 0000000000..68c09ef04f --- /dev/null +++ b/patches/unapplied/server/1054-Improve-cancelling-PreCreatureSpawnEvent-with-per-pl.patch @@ -0,0 +1,89 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: kickash32 <[email protected]> +Date: Mon, 5 Apr 2021 01:42:35 -0400 +Subject: [PATCH] Improve cancelling PreCreatureSpawnEvent with per player mob + spawns + + +diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java +index 094096bd08450e5d656ce2c442757cbc63ffb090..cfeeddf2cb4ff50dbc29c6913e78ca1dee076790 100644 +--- a/src/main/java/net/minecraft/server/level/ChunkMap.java ++++ b/src/main/java/net/minecraft/server/level/ChunkMap.java +@@ -246,8 +246,25 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider + ++(backingSet[i].mobCounts[index]); + } + } ++ // Paper start - per player mob count backoff ++ public void updateFailurePlayerMobTypeMap(int chunkX, int chunkZ, net.minecraft.world.entity.MobCategory mobCategory) { ++ if (!this.level.paperConfig().entities.spawning.perPlayerMobSpawns) { ++ return; ++ } ++ int idx = mobCategory.ordinal(); ++ final ca.spottedleaf.moonrise.common.list.ReferenceList<ServerPlayer> inRange = ++ this.level.moonrise$getNearbyPlayers().getPlayersByChunk(chunkX, chunkZ, ca.spottedleaf.moonrise.common.misc.NearbyPlayers.NearbyMapType.TICK_VIEW_DISTANCE); ++ if (inRange == null) { ++ return; ++ } ++ final ServerPlayer[] backingSet = inRange.getRawDataUnchecked(); ++ for (int i = 0, len = inRange.size(); i < len; i++) { ++ ++(backingSet[i].mobBackoffCounts[idx]); ++ } ++ } ++ // Paper end - per player mob count backoff + public int getMobCountNear(final ServerPlayer player, final net.minecraft.world.entity.MobCategory mobCategory) { +- return player.mobCounts[mobCategory.ordinal()]; ++ return player.mobCounts[mobCategory.ordinal()] + player.mobBackoffCounts[mobCategory.ordinal()]; // Paper - per player mob count backoff + // Paper end - Optional per player mob spawns + } + // Paper end +diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java +index 8e96905fa93b02623f16feb4369a45b175031ebf..d021cd5b6136f0125076513977f430c6d4dd4f9f 100644 +--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java ++++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java +@@ -555,7 +555,17 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon + 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) { +- Arrays.fill(player.mobCounts, 0); ++ // Paper start - per player mob spawning backoff ++ for (int ii = 0; ii < ServerPlayer.MOBCATEGORY_TOTAL_ENUMS; ii++) { ++ player.mobCounts[ii] = 0; ++ ++ int newBackoff = player.mobBackoffCounts[ii] - 1; // TODO make configurable bleed // TODO use nonlinear algorithm? ++ if (newBackoff < 0) { ++ newBackoff = 0; ++ } ++ player.mobBackoffCounts[ii] = newBackoff; ++ } ++ // Paper end - per player mob spawning backoff + } + spawnercreature_d = NaturalSpawner.createState(naturalSpawnChunkCount, this.level.getAllEntities(), this::getFullChunk, null, true); + } else { +diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java +index 2b40896483ffbba2c84dbaaae3194342ed5d2170..a755a2742f18ed55adc1fc735d995c9874b1e62e 100644 +--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java ++++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java +@@ -307,6 +307,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple + public static final int MOBCATEGORY_TOTAL_ENUMS = net.minecraft.world.entity.MobCategory.values().length; + public final int[] mobCounts = new int[MOBCATEGORY_TOTAL_ENUMS]; // Paper + // Paper end - Optional per player mob spawns ++ public final int[] mobBackoffCounts = new int[MOBCATEGORY_TOTAL_ENUMS]; // Paper - per player mob count backoff + + // CraftBukkit start + public CraftPlayer.TransferCookieConnection transferCookieConnection; +diff --git a/src/main/java/net/minecraft/world/level/NaturalSpawner.java b/src/main/java/net/minecraft/world/level/NaturalSpawner.java +index 12ebd7829c7f6814ccd79ae96aa9023afcc64696..c1b76a1ebc1eea7ab70cf61d8175a31794dd122a 100644 +--- a/src/main/java/net/minecraft/world/level/NaturalSpawner.java ++++ b/src/main/java/net/minecraft/world/level/NaturalSpawner.java +@@ -299,6 +299,11 @@ public final class NaturalSpawner { + + // Paper start - PreCreatureSpawnEvent + PreSpawnStatus doSpawning = isValidSpawnPostitionForType(world, group, structuremanager, chunkgenerator, biomesettingsmobs_c, blockposition_mutableblockposition, d2); ++ // Paper start - per player mob count backoff ++ if (doSpawning == PreSpawnStatus.ABORT || doSpawning == PreSpawnStatus.CANCELLED) { ++ world.getChunkSource().chunkMap.updateFailurePlayerMobTypeMap(blockposition_mutableblockposition.getX() >> 4, blockposition_mutableblockposition.getZ() >> 4, group); ++ } ++ // Paper end - per player mob count backoff + if (doSpawning == PreSpawnStatus.ABORT) { + return; + } |