craftbukkit/nms-patches/net/minecraft/world/level/SpawnerCreature.patch

122 lines
7.6 KiB
Diff
Raw Normal View History

2021-03-16 09:00:00 +11:00
--- a/net/minecraft/world/level/SpawnerCreature.java
+++ b/net/minecraft/world/level/SpawnerCreature.java
2021-06-11 15:00:00 +10:00
@@ -47,6 +47,11 @@
2018-07-15 10:00:00 +10:00
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2016-07-15 20:08:04 +10:00
+// CraftBukkit start
2021-03-16 09:00:00 +11:00
+import net.minecraft.world.level.storage.WorldData;
+import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
+// CraftBukkit end
2016-07-15 20:08:04 +10:00
+
public final class SpawnerCreature {
2019-04-25 12:00:00 +10:00
private static final Logger LOGGER = LogManager.getLogger();
2021-06-11 15:00:00 +10:00
@@ -73,7 +78,8 @@
2020-06-25 10:00:00 +10:00
if (entity instanceof EntityInsentient) {
EntityInsentient entityinsentient = (EntityInsentient) entity;
2021-11-22 09:00:00 +11:00
- if (entityinsentient.isPersistenceRequired() || entityinsentient.requiresCustomPersistence()) {
2020-06-25 10:00:00 +10:00
+ // CraftBukkit - Split out persistent check, don't apply it to special persistent mobs
2021-11-22 09:00:00 +11:00
+ if (entityinsentient.removeWhenFarAway(0) && entityinsentient.isPersistenceRequired()) {
2020-06-25 10:00:00 +10:00
continue;
}
}
2021-11-22 09:00:00 +11:00
@@ -111,10 +117,54 @@
2021-06-11 15:00:00 +10:00
EnumCreatureType[] aenumcreaturetype = SpawnerCreature.SPAWNING_CATEGORIES;
2020-06-25 10:00:00 +10:00
int i = aenumcreaturetype.length;
+ // CraftBukkit start - Other mob type spawn tick rate
2021-11-22 09:00:00 +11:00
+ 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;
2020-06-25 10:00:00 +10:00
+ // CraftBukkit end
+
for (int j = 0; j < i; ++j) {
EnumCreatureType enumcreaturetype = aenumcreaturetype[j];
+ // CraftBukkit start - Use per-world spawn limits
+ boolean spawnThisTick = true;
2021-11-22 09:00:00 +11:00
+ int limit = enumcreaturetype.getMaxInstancesPerChunk();
2020-06-25 10:00:00 +10:00
+ 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;
2020-06-25 10:00:00 +10:00
+ case AMBIENT:
+ spawnThisTick = spawnAmbientThisTick;
+ limit = worldserver.getWorld().getAmbientSpawnLimit();
+ break;
+ case WATER_AMBIENT:
+ spawnThisTick = spawnWaterAmbientThisTick;
+ limit = worldserver.getWorld().getWaterAmbientSpawnLimit();
+ break;
2020-06-25 10:00:00 +10:00
+ }
2021-11-22 09:00:00 +11:00
- if ((flag || !enumcreaturetype.isFriendly()) && (flag1 || enumcreaturetype.isFriendly()) && (flag2 || !enumcreaturetype.isPersistent()) && spawnercreature_d.canSpawnForCategory(enumcreaturetype, chunk.getPos())) {
2020-06-25 10:00:00 +10:00
+ if (!spawnThisTick || limit == 0) {
+ continue;
+ }
+
2021-11-22 09:00:00 +11:00
+ if ((flag || !enumcreaturetype.isFriendly()) && (flag1 || enumcreaturetype.isFriendly()) && (flag2 || !enumcreaturetype.isPersistent()) && spawnercreature_d.canSpawnForCategory(enumcreaturetype, chunk.getPos(), limit)) {
2020-06-25 10:00:00 +10:00
+ // CraftBukkit end
2021-06-11 15:00:00 +10:00
Objects.requireNonNull(spawnercreature_d);
2021-11-22 09:00:00 +11:00
SpawnerCreature.c spawnercreature_c = spawnercreature_d::canSpawn;
2021-06-11 15:00:00 +10:00
2021-11-22 09:00:00 +11:00
@@ -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);
2020-06-25 10:00:00 +10:00
- ++j;
- ++k1;
2021-11-22 09:00:00 +11:00
- worldserver.addFreshEntityWithPassengers(entityinsentient);
2020-06-25 10:00:00 +10:00
- spawnercreature_a.run(entityinsentient, ichunkaccess);
+ // CraftBukkit start
2021-11-22 09:00:00 +11:00
+ worldserver.addFreshEntityWithPassengers(entityinsentient, SpawnReason.NATURAL);
2021-06-11 15:00:00 +10:00
+ if (!entityinsentient.isRemoved()) {
2020-06-25 10:00:00 +10:00
+ ++j;
+ ++k1;
+ spawnercreature_a.run(entityinsentient, ichunkaccess);
+ }
+ // CraftBukkit end
2021-11-22 09:00:00 +11:00
if (j >= entityinsentient.getMaxSpawnClusterSize()) {
2020-06-25 10:00:00 +10:00
return;
}
2021-11-22 09:00:00 +11:00
@@ -377,7 +431,7 @@
2019-04-23 12:00:00 +10:00
2021-11-22 09:00:00 +11:00
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
2021-06-11 15:00:00 +10:00
flag = true;
}
}
2021-11-22 09:00:00 +11:00
@@ -498,8 +552,10 @@
2021-06-11 15:00:00 +10:00
return this.unmodifiableMobCategoryCounts;
2020-06-25 10:00:00 +10:00
}
2021-11-22 09:00:00 +11:00
- boolean canSpawnForCategory(EnumCreatureType enumcreaturetype, ChunkCoordIntPair chunkcoordintpair) {
- int i = enumcreaturetype.getMaxInstancesPerChunk() * this.spawnableChunkCount / SpawnerCreature.MAGIC_NUMBER;
2020-06-25 10:00:00 +10:00
+ // CraftBukkit start
2021-11-22 09:00:00 +11:00
+ boolean canSpawnForCategory(EnumCreatureType enumcreaturetype, ChunkCoordIntPair chunkcoordintpair, int limit) {
2021-06-11 15:00:00 +10:00
+ int i = limit * this.spawnableChunkCount / SpawnerCreature.MAGIC_NUMBER;
2020-06-25 10:00:00 +10:00
+ // CraftBukkit end
2021-11-22 09:00:00 +11:00
return this.mobCategoryCounts.getInt(enumcreaturetype) >= i ? false : this.localMobCapCalculator.canSpawn(enumcreaturetype, chunkcoordintpair);
2020-06-25 10:00:00 +10:00
}