From 2cd6ace7ab4d1c0012fdc332c39eca285ee18ef7 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sun, 24 Mar 2019 01:01:32 -0400 Subject: [PATCH] Only count Natural Spawned mobs towards natural spawn mob limit This resolves the super common complaint about mobs not spawning. This was ultimately a flaw in the vanilla count algorithim that allows spawners and other misc mobs to count against the mob limit, which are not bounded, and can prevent the entire world from spawning new. I believe Bukkits changes around persistence may of actually made it worse than vanilla. This should fully solve all of the issues around it so that only natural influences natural spawns. --- .../world/level/NaturalSpawner.java.patch | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/paper-server/patches/sources/net/minecraft/world/level/NaturalSpawner.java.patch b/paper-server/patches/sources/net/minecraft/world/level/NaturalSpawner.java.patch index 93915cc03d..b3642f7fcf 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/NaturalSpawner.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/NaturalSpawner.java.patch @@ -14,7 +14,21 @@ public final class NaturalSpawner { -@@ -107,15 +112,31 @@ +@@ -82,6 +87,13 @@ + MobCategory enumcreaturetype = entity.getType().getCategory(); + + if (enumcreaturetype != MobCategory.MISC) { ++ // Paper start - Only count natural spawns ++ if (!entity.level().paperConfig().entities.spawning.countAllMobsForSpawning && ++ !(entity.spawnReason == org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL || ++ entity.spawnReason == org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.CHUNK_GEN)) { ++ continue; ++ } ++ // Paper end - Only count natural spawns + BlockPos blockposition = entity.blockPosition(); + + chunkSource.query(ChunkPos.asLong(blockposition), (chunk) -> { +@@ -107,15 +119,31 @@ return (Biome) chunk.getNoiseBiome(QuartPos.fromBlock(pos.getX()), QuartPos.fromBlock(pos.getY()), QuartPos.fromBlock(pos.getZ())).value(); } @@ -48,7 +62,7 @@ list.add(enumcreaturetype); } } -@@ -164,9 +185,9 @@ +@@ -164,9 +192,9 @@ StructureManager structuremanager = world.structureManager(); ChunkGenerator chunkgenerator = world.getChunkSource().getGenerator(); int i = pos.getY(); @@ -60,7 +74,7 @@ BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos(); int j = 0; int k = 0; -@@ -195,7 +216,7 @@ +@@ -195,7 +223,7 @@ if (entityhuman != null) { double d2 = entityhuman.distanceToSqr(d0, (double) i, d1); @@ -69,7 +83,7 @@ if (biomesettingsmobs_c == null) { Optional optional = NaturalSpawner.getRandomSpawnMobAt(world, structuremanager, chunkgenerator, group, world.random, blockposition_mutableblockposition); -@@ -207,7 +228,13 @@ +@@ -207,7 +235,13 @@ j1 = biomesettingsmobs_c.minCount + world.random.nextInt(1 + biomesettingsmobs_c.maxCount - biomesettingsmobs_c.minCount); } @@ -84,7 +98,7 @@ Mob entityinsentient = NaturalSpawner.getMobForSpawn(world, biomesettingsmobs_c.type); if (entityinsentient == null) { -@@ -217,10 +244,15 @@ +@@ -217,10 +251,15 @@ entityinsentient.moveTo(d0, (double) i, d1, world.random.nextFloat() * 360.0F, 0.0F); if (NaturalSpawner.isValidPositionForMob(world, entityinsentient, d2)) { groupdataentity = entityinsentient.finalizeSpawn(world, world.getCurrentDifficultyAt(entityinsentient.blockPosition()), EntitySpawnReason.NATURAL, groupdataentity); @@ -104,7 +118,7 @@ if (j >= entityinsentient.getMaxSpawnClusterSize()) { return; } -@@ -250,10 +282,31 @@ +@@ -250,10 +289,31 @@ return squaredDistance <= 576.0D ? false : (world.getSharedSpawnPos().closerToCenterThan(new Vec3((double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D), 24.0D) ? false : Objects.equals(new ChunkPos(pos), chunk.getPos()) || world.isNaturalSpawningAllowed((BlockPos) pos)); } @@ -138,7 +152,7 @@ } @Nullable -@@ -268,6 +321,7 @@ +@@ -268,6 +328,7 @@ NaturalSpawner.LOGGER.warn("Can't spawn entity of type: {}", BuiltInRegistries.ENTITY_TYPE.getKey(type)); } catch (Exception exception) { NaturalSpawner.LOGGER.warn("Failed to create mob", exception); @@ -146,7 +160,7 @@ } return null; -@@ -356,6 +410,7 @@ +@@ -356,6 +417,7 @@ entity = biomesettingsmobs_c.type.create(world.getLevel(), EntitySpawnReason.NATURAL); } catch (Exception exception) { NaturalSpawner.LOGGER.warn("Failed to create mob", exception); @@ -154,7 +168,7 @@ continue; } -@@ -369,7 +424,7 @@ +@@ -369,7 +431,7 @@ if (entityinsentient.checkSpawnRules(world, EntitySpawnReason.CHUNK_GENERATION) && entityinsentient.checkSpawnObstruction(world)) { groupdataentity = entityinsentient.finalizeSpawn(world, world.getCurrentDifficultyAt(entityinsentient.blockPosition()), EntitySpawnReason.CHUNK_GENERATION, groupdataentity); @@ -163,7 +177,7 @@ flag = true; } } -@@ -482,10 +537,12 @@ +@@ -482,10 +544,12 @@ return this.unmodifiableMobCategoryCounts; }