mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-09 19:49:35 +01:00
65bc2541a3
By: md_5 <git@md-5.net>
85 lines
5.8 KiB
Diff
85 lines
5.8 KiB
Diff
--- a/net/minecraft/world/level/SpawnerCreature.java
|
|
+++ b/net/minecraft/world/level/SpawnerCreature.java
|
|
@@ -46,6 +46,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();
|
|
@@ -108,10 +115,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;
|
|
|
|
@@ -196,10 +218,15 @@
|
|
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);
|
|
- ++j;
|
|
- ++k1;
|
|
- worldserver.addFreshEntityWithPassengers(entityinsentient);
|
|
- spawnercreature_a.run(entityinsentient, ichunkaccess);
|
|
+ // CraftBukkit start
|
|
+ // SPIGOT-7045: Give ocelot babies back their special spawn reason. Note: This is the only modification required as ocelots count as monsters which means they only spawn during normal chunk ticking and do not spawn during chunk generation as starter mobs.
|
|
+ worldserver.addFreshEntityWithPassengers(entityinsentient, (entityinsentient instanceof net.minecraft.world.entity.animal.EntityOcelot && !((org.bukkit.entity.Ageable) entityinsentient.getBukkitEntity()).isAdult()) ? SpawnReason.OCELOT_BABY : SpawnReason.NATURAL);
|
|
+ if (!entityinsentient.isRemoved()) {
|
|
+ ++j;
|
|
+ ++k1;
|
|
+ spawnercreature_a.run(entityinsentient, ichunkaccess);
|
|
+ }
|
|
+ // CraftBukkit end
|
|
if (j >= entityinsentient.getMaxSpawnClusterSize()) {
|
|
return;
|
|
}
|
|
@@ -348,7 +375,7 @@
|
|
|
|
if (entityinsentient.checkSpawnRules(worldaccess, EnumMobSpawn.CHUNK_GENERATION) && entityinsentient.checkSpawnObstruction(worldaccess)) {
|
|
groupdataentity = entityinsentient.finalizeSpawn(worldaccess, worldaccess.getCurrentDifficultyAt(entityinsentient.blockPosition()), EnumMobSpawn.CHUNK_GENERATION, groupdataentity);
|
|
- worldaccess.addFreshEntityWithPassengers(entityinsentient);
|
|
+ worldaccess.addFreshEntityWithPassengers(entityinsentient, SpawnReason.CHUNK_GEN); // CraftBukkit
|
|
flag = true;
|
|
}
|
|
}
|
|
@@ -461,8 +488,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);
|
|
}
|