PaperMC/paper-server/nms-patches/net/minecraft/world/level/SpawnerCreature.patch
CraftBukkit/Spigot 9ee989ea81 Update to Minecraft 1.18.2
By: md_5 <git@md-5.net>
2022-03-01 02:00:00 +11:00

94 lines
5.9 KiB
Diff

--- a/net/minecraft/world/level/SpawnerCreature.java
+++ b/net/minecraft/world/level/SpawnerCreature.java
@@ -47,6 +47,13 @@
import net.minecraft.world.phys.Vec3D;
import org.slf4j.Logger;
+// CraftBukkit start
+import net.minecraft.world.level.storage.WorldData;
+import org.bukkit.craftbukkit.util.CraftSpawnCategory;
+import org.bukkit.entity.SpawnCategory;
+import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
+// CraftBukkit end
+
public final class SpawnerCreature {
private static final Logger LOGGER = LogUtils.getLogger();
@@ -73,7 +80,8 @@
if (entity instanceof EntityInsentient) {
EntityInsentient entityinsentient = (EntityInsentient) entity;
- if (entityinsentient.isPersistenceRequired() || entityinsentient.requiresCustomPersistence()) {
+ // CraftBukkit - Split out persistent check, don't apply it to special persistent mobs
+ if (entityinsentient.removeWhenFarAway(0) && entityinsentient.isPersistenceRequired()) {
continue;
}
}
@@ -111,10 +119,25 @@
EnumCreatureType[] aenumcreaturetype = SpawnerCreature.SPAWNING_CATEGORIES;
int i = aenumcreaturetype.length;
+ WorldData worlddata = worldserver.getLevelData(); // CraftBukkit - Other mob type spawn tick rate
+
for (int j = 0; j < i; ++j) {
EnumCreatureType enumcreaturetype = aenumcreaturetype[j];
+ // CraftBukkit start - Use per-world spawn limits
+ boolean spawnThisTick = true;
+ int limit = enumcreaturetype.getMaxInstancesPerChunk();
+ SpawnCategory spawnCategory = CraftSpawnCategory.toBukkit(enumcreaturetype);
+ if (CraftSpawnCategory.isValidForLimits(spawnCategory)) {
+ spawnThisTick = worldserver.ticksPerSpawnCategory.getLong(spawnCategory) != 0 && worlddata.getGameTime() % worldserver.ticksPerSpawnCategory.getLong(spawnCategory) == 0;
+ limit = worldserver.getWorld().getSpawnLimit(spawnCategory);
+ }
- if ((flag || !enumcreaturetype.isFriendly()) && (flag1 || enumcreaturetype.isFriendly()) && (flag2 || !enumcreaturetype.isPersistent()) && spawnercreature_d.canSpawnForCategory(enumcreaturetype, chunk.getPos())) {
+ if (!spawnThisTick || limit == 0) {
+ continue;
+ }
+
+ if ((flag || !enumcreaturetype.isFriendly()) && (flag1 || enumcreaturetype.isFriendly()) && (flag2 || !enumcreaturetype.isPersistent()) && spawnercreature_d.canSpawnForCategory(enumcreaturetype, chunk.getPos(), limit)) {
+ // CraftBukkit end
Objects.requireNonNull(spawnercreature_d);
SpawnerCreature.c spawnercreature_c = spawnercreature_d::canSpawn;
@@ -199,10 +222,14 @@
entityinsentient.moveTo(d0, (double) i, d1, worldserver.random.nextFloat() * 360.0F, 0.0F);
if (isValidPositionForMob(worldserver, entityinsentient, d2)) {
groupdataentity = entityinsentient.finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(entityinsentient.blockPosition()), EnumMobSpawn.NATURAL, groupdataentity, (NBTTagCompound) null);
- ++j;
- ++k1;
- worldserver.addFreshEntityWithPassengers(entityinsentient);
- spawnercreature_a.run(entityinsentient, ichunkaccess);
+ // CraftBukkit start
+ worldserver.addFreshEntityWithPassengers(entityinsentient, SpawnReason.NATURAL);
+ if (!entityinsentient.isRemoved()) {
+ ++j;
+ ++k1;
+ spawnercreature_a.run(entityinsentient, ichunkaccess);
+ }
+ // CraftBukkit end
if (j >= entityinsentient.getMaxSpawnClusterSize()) {
return;
}
@@ -383,7 +410,7 @@
if (entityinsentient.checkSpawnRules(worldaccess, EnumMobSpawn.CHUNK_GENERATION) && entityinsentient.checkSpawnObstruction(worldaccess)) {
groupdataentity = entityinsentient.finalizeSpawn(worldaccess, worldaccess.getCurrentDifficultyAt(entityinsentient.blockPosition()), EnumMobSpawn.CHUNK_GENERATION, groupdataentity, (NBTTagCompound) null);
- worldaccess.addFreshEntityWithPassengers(entityinsentient);
+ worldaccess.addFreshEntityWithPassengers(entityinsentient, SpawnReason.CHUNK_GEN); // CraftBukkit
flag = true;
}
}
@@ -504,8 +531,10 @@
return this.unmodifiableMobCategoryCounts;
}
- boolean canSpawnForCategory(EnumCreatureType enumcreaturetype, ChunkCoordIntPair chunkcoordintpair) {
- int i = enumcreaturetype.getMaxInstancesPerChunk() * this.spawnableChunkCount / SpawnerCreature.MAGIC_NUMBER;
+ // CraftBukkit start
+ boolean canSpawnForCategory(EnumCreatureType enumcreaturetype, ChunkCoordIntPair chunkcoordintpair, int limit) {
+ int i = limit * this.spawnableChunkCount / SpawnerCreature.MAGIC_NUMBER;
+ // CraftBukkit end
return this.mobCategoryCounts.getInt(enumcreaturetype) >= i ? false : this.localMobCapCalculator.canSpawn(enumcreaturetype, chunkcoordintpair);
}