mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-09 19:49:35 +01:00
43702a9e10
By: md_5 <git@md-5.net>
121 lines
7.6 KiB
Diff
121 lines
7.6 KiB
Diff
--- a/net/minecraft/world/level/SpawnerCreature.java
|
|
+++ b/net/minecraft/world/level/SpawnerCreature.java
|
|
@@ -47,6 +47,11 @@
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
+// CraftBukkit start
|
|
+import net.minecraft.world.level.storage.WorldData;
|
|
+import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
|
+// CraftBukkit end
|
|
+
|
|
public final class SpawnerCreature {
|
|
|
|
private static final Logger LOGGER = LogManager.getLogger();
|
|
@@ -73,7 +78,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 +117,54 @@
|
|
EnumCreatureType[] aenumcreaturetype = SpawnerCreature.SPAWNING_CATEGORIES;
|
|
int i = aenumcreaturetype.length;
|
|
|
|
+ // CraftBukkit start - Other mob type spawn tick rate
|
|
+ WorldData worlddata = worldserver.getLevelData();
|
|
+ boolean spawnAnimalThisTick = worldserver.ticksPerAnimalSpawns != 0L && worlddata.getGameTime() % worldserver.ticksPerAnimalSpawns == 0L;
|
|
+ boolean spawnMonsterThisTick = worldserver.ticksPerMonsterSpawns != 0L && worlddata.getGameTime() % worldserver.ticksPerMonsterSpawns == 0L;
|
|
+ boolean spawnWaterThisTick = worldserver.ticksPerWaterSpawns != 0L && worlddata.getGameTime() % worldserver.ticksPerWaterSpawns == 0L;
|
|
+ boolean spawnAmbientThisTick = worldserver.ticksPerAmbientSpawns != 0L && worlddata.getGameTime() % worldserver.ticksPerAmbientSpawns == 0L;
|
|
+ boolean spawnWaterAmbientThisTick = worldserver.ticksPerWaterAmbientSpawns != 0L && worlddata.getGameTime() % worldserver.ticksPerWaterAmbientSpawns == 0L;
|
|
+ boolean spawnWaterUndergroundCreatureThisTick = worldserver.ticksPerWaterUndergroundCreatureSpawns != 0L && worlddata.getGameTime() % worldserver.ticksPerWaterUndergroundCreatureSpawns == 0L;
|
|
+ // CraftBukkit end
|
|
+
|
|
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();
|
|
+ switch (enumcreaturetype) {
|
|
+ case MONSTER:
|
|
+ spawnThisTick = spawnMonsterThisTick;
|
|
+ limit = worldserver.getWorld().getMonsterSpawnLimit();
|
|
+ break;
|
|
+ case CREATURE:
|
|
+ spawnThisTick = spawnAnimalThisTick;
|
|
+ limit = worldserver.getWorld().getAnimalSpawnLimit();
|
|
+ break;
|
|
+ case WATER_CREATURE:
|
|
+ spawnThisTick = spawnWaterThisTick;
|
|
+ limit = worldserver.getWorld().getWaterAnimalSpawnLimit();
|
|
+ break;
|
|
+ case UNDERGROUND_WATER_CREATURE:
|
|
+ spawnThisTick = spawnWaterUndergroundCreatureThisTick;
|
|
+ limit = worldserver.getWorld().getWaterUndergroundCreatureSpawnLimit();
|
|
+ break;
|
|
+ case AMBIENT:
|
|
+ spawnThisTick = spawnAmbientThisTick;
|
|
+ limit = worldserver.getWorld().getAmbientSpawnLimit();
|
|
+ break;
|
|
+ case WATER_AMBIENT:
|
|
+ spawnThisTick = spawnWaterAmbientThisTick;
|
|
+ limit = worldserver.getWorld().getWaterAmbientSpawnLimit();
|
|
+ break;
|
|
+ }
|
|
|
|
- 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 +249,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;
|
|
}
|
|
@@ -377,7 +431,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;
|
|
}
|
|
}
|
|
@@ -498,8 +552,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);
|
|
}
|