Paper/nms-patches/SpawnerCreature.patch

115 lines
6.5 KiB
Diff
Raw Normal View History

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/SpawnerCreature.java
+++ b/net/minecraft/server/SpawnerCreature.java
2020-06-25 02:00:00 +02:00
@@ -13,6 +13,10 @@
2018-07-15 02:00:00 +02:00
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2016-07-15 12:08:04 +02:00
+// CraftBukkit start
+import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
+// CraftBukkit end
2016-07-15 12:08:04 +02:00
+
public final class SpawnerCreature {
2019-04-25 04:00:00 +02:00
private static final Logger LOGGER = LogManager.getLogger();
2020-06-25 02:00:00 +02:00
@@ -34,7 +38,8 @@
if (entity instanceof EntityInsentient) {
EntityInsentient entityinsentient = (EntityInsentient) entity;
- if (entityinsentient.isPersistent() || entityinsentient.isSpecialPersistence()) {
+ // CraftBukkit - Split out persistent check, don't apply it to special persistent mobs
+ if (entityinsentient.isTypeNotPersistent(0) && entityinsentient.isPersistent()) {
continue;
}
}
2020-08-11 23:00:00 +02:00
@@ -69,10 +74,49 @@
2020-06-25 02:00:00 +02:00
EnumCreatureType[] aenumcreaturetype = SpawnerCreature.c;
int i = aenumcreaturetype.length;
+ // CraftBukkit start - Other mob type spawn tick rate
+ WorldData worlddata = worldserver.getWorldData();
+ boolean spawnAnimalThisTick = worldserver.ticksPerAnimalSpawns != 0L && worlddata.getTime() % worldserver.ticksPerAnimalSpawns == 0L;
+ boolean spawnMonsterThisTick = worldserver.ticksPerMonsterSpawns != 0L && worlddata.getTime() % worldserver.ticksPerMonsterSpawns == 0L;
+ boolean spawnWaterThisTick = worldserver.ticksPerWaterSpawns != 0L && worlddata.getTime() % worldserver.ticksPerWaterSpawns == 0L;
+ boolean spawnAmbientThisTick = worldserver.ticksPerAmbientSpawns != 0L && worlddata.getTime() % worldserver.ticksPerAmbientSpawns == 0L;
+ boolean spawnWaterAmbientThisTick = worldserver.ticksPerWaterAmbientSpawns != 0L && worlddata.getTime() % worldserver.ticksPerWaterAmbientSpawns == 0L;
2020-06-25 02:00:00 +02:00
+ // 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.c();
+ 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 AMBIENT:
+ spawnThisTick = spawnAmbientThisTick;
+ limit = worldserver.getWorld().getAmbientSpawnLimit();
+ break;
+ case WATER_AMBIENT:
+ spawnThisTick = spawnWaterAmbientThisTick;
+ limit = worldserver.getWorld().getWaterAmbientSpawnLimit();
+ break;
2020-06-25 02:00:00 +02:00
+ }
- if ((flag || !enumcreaturetype.d()) && (flag1 || enumcreaturetype.d()) && (flag2 || !enumcreaturetype.e()) && spawnercreature_d.a(enumcreaturetype)) {
+ if (!spawnThisTick || limit == 0) {
+ continue;
+ }
+
+ if ((flag || !enumcreaturetype.d()) && (flag1 || enumcreaturetype.d()) && (flag2 || !enumcreaturetype.e()) && spawnercreature_d.a(enumcreaturetype, limit)) {
+ // CraftBukkit end
a(enumcreaturetype, worldserver, chunk, (entitytypes, blockposition, ichunkaccess) -> {
return spawnercreature_d.a(entitytypes, blockposition, ichunkaccess);
}, (entityinsentient, ichunkaccess) -> {
2020-08-11 23:00:00 +02:00
@@ -147,10 +191,13 @@
2020-06-25 02:00:00 +02:00
entityinsentient.setPositionRotation(d0, (double) i, d1, worldserver.random.nextFloat() * 360.0F, 0.0F);
if (a(worldserver, entityinsentient, d2)) {
groupdataentity = entityinsentient.prepare(worldserver, worldserver.getDamageScaler(entityinsentient.getChunkCoordinates()), EnumMobSpawn.NATURAL, groupdataentity, (NBTTagCompound) null);
- ++j;
- ++k1;
2020-08-11 23:00:00 +02:00
- worldserver.addAllEntities(entityinsentient);
2020-06-25 02:00:00 +02:00
- spawnercreature_a.run(entityinsentient, ichunkaccess);
+ // CraftBukkit start
2020-08-11 23:00:00 +02:00
+ if (worldserver.addAllEntities(entityinsentient, SpawnReason.NATURAL)) {
2020-06-25 02:00:00 +02:00
+ ++j;
+ ++k1;
+ spawnercreature_a.run(entityinsentient, ichunkaccess);
+ }
+ // CraftBukkit end
if (j >= entityinsentient.getMaxSpawnGroup()) {
return;
}
@@ -333,7 +380,7 @@
2019-04-23 04:00:00 +02:00
2020-08-11 23:00:00 +02:00
if (entityinsentient.a((GeneratorAccess) worldaccess, EnumMobSpawn.CHUNK_GENERATION) && entityinsentient.a((IWorldReader) worldaccess)) {
groupdataentity = entityinsentient.prepare(worldaccess, worldaccess.getDamageScaler(entityinsentient.getChunkCoordinates()), EnumMobSpawn.CHUNK_GENERATION, groupdataentity, (NBTTagCompound) null);
- worldaccess.addAllEntities(entityinsentient);
+ worldaccess.addAllEntities(entityinsentient, SpawnReason.CHUNK_GEN); // CraftBukkit
2019-04-23 04:00:00 +02:00
flag = true;
}
}
2020-08-11 23:00:00 +02:00
@@ -456,8 +503,10 @@
2020-06-25 02:00:00 +02:00
return this.d;
}
- private boolean a(EnumCreatureType enumcreaturetype) {
- int i = enumcreaturetype.c() * this.a / SpawnerCreature.b;
+ // CraftBukkit start
+ private boolean a(EnumCreatureType enumcreaturetype, int limit) {
+ int i = limit * this.a / SpawnerCreature.b;
+ // CraftBukkit end
return this.b.getInt(enumcreaturetype) < i;
}