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

90 lines
5.9 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
2025-03-26 03:05:00 +11:00
@@ -49,6 +49,13 @@
2022-03-01 02:00:00 +11:00
import net.minecraft.world.phys.Vec3D;
import org.slf4j.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.craftbukkit.util.CraftSpawnCategory;
+import org.bukkit.entity.SpawnCategory;
+import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
+// CraftBukkit end
2016-07-15 20:08:04 +10:00
+
public final class SpawnerCreature {
2022-03-01 02:00:00 +11:00
private static final Logger LOGGER = LogUtils.getLogger();
2025-03-26 03:05:00 +11:00
@@ -104,11 +111,28 @@
2024-10-23 02:15:00 +11:00
return (BiomeBase) ichunkaccess.getNoiseBiome(QuartPos.fromBlock(blockposition.getX()), QuartPos.fromBlock(blockposition.getY()), QuartPos.fromBlock(blockposition.getZ())).value();
}
- public static List<EnumCreatureType> getFilteredSpawningCategories(SpawnerCreature.d spawnercreature_d, boolean flag, boolean flag1, boolean flag2) {
+ // CraftBukkit start - add server
+ public static List<EnumCreatureType> getFilteredSpawningCategories(SpawnerCreature.d spawnercreature_d, boolean flag, boolean flag1, boolean flag2, WorldServer worldserver) {
+ WorldData worlddata = worldserver.getLevelData(); // CraftBukkit - Other mob type spawn tick rate
+ // CraftBukkit end
List<EnumCreatureType> list = new ArrayList(SpawnerCreature.SPAWNING_CATEGORIES.length);
2020-06-25 10:00:00 +10:00
2025-03-26 03:05:00 +11:00
for (EnumCreatureType enumcreaturetype : SpawnerCreature.SPAWNING_CATEGORIES) {
- if ((flag || !enumcreaturetype.isFriendly()) && (flag1 || enumcreaturetype.isFriendly()) && (flag2 || !enumcreaturetype.isPersistent()) && spawnercreature_d.canSpawnForCategoryGlobal(enumcreaturetype)) {
2020-06-25 10:00:00 +10:00
+ // CraftBukkit start - Use per-world spawn limits
+ boolean spawnThisTick = true;
2021-11-22 09:00:00 +11:00
+ 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);
2020-06-25 10:00:00 +10:00
+ }
2025-03-26 03:05:00 +11:00
+
2020-06-25 10:00:00 +10:00
+ if (!spawnThisTick || limit == 0) {
+ continue;
+ }
+
2024-10-23 02:15:00 +11:00
+ if ((flag || !enumcreaturetype.isFriendly()) && (flag1 || enumcreaturetype.isFriendly()) && (flag2 || !enumcreaturetype.isPersistent()) && spawnercreature_d.canSpawnForCategoryGlobal(enumcreaturetype, limit)) {
2020-06-25 10:00:00 +10:00
+ // CraftBukkit end
2024-10-23 02:15:00 +11:00
list.add(enumcreaturetype);
}
}
2025-03-26 03:05:00 +11:00
@@ -202,10 +226,15 @@
entityinsentient.snapTo(d0, (double) i, d1, worldserver.random.nextFloat() * 360.0F, 0.0F);
if (isValidPositionForMob(worldserver, entityinsentient, d2)) {
groupdataentity = entityinsentient.finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(entityinsentient.blockPosition()), EntitySpawnReason.NATURAL, groupdataentity);
- ++j;
- ++l1;
- 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;
+ ++l1;
+ spawnercreature_a.run(entityinsentient, ichunkaccess);
+ }
+ // CraftBukkit end
if (j >= entityinsentient.getMaxSpawnClusterSize()) {
return;
}
@@ -354,7 +383,7 @@
2019-04-23 12:00:00 +10:00
2024-10-23 02:15:00 +11:00
if (entityinsentient.checkSpawnRules(worldaccess, EntitySpawnReason.CHUNK_GENERATION) && entityinsentient.checkSpawnObstruction(worldaccess)) {
groupdataentity = entityinsentient.finalizeSpawn(worldaccess, worldaccess.getCurrentDifficultyAt(entityinsentient.blockPosition()), EntitySpawnReason.CHUNK_GENERATION, groupdataentity);
2021-11-22 09:00:00 +11:00
- worldaccess.addFreshEntityWithPassengers(entityinsentient);
+ worldaccess.addFreshEntityWithPassengers(entityinsentient, SpawnReason.CHUNK_GEN); // CraftBukkit
2021-06-11 15:00:00 +10:00
flag = true;
}
}
2025-03-26 03:05:00 +11:00
@@ -461,8 +490,10 @@
2021-06-11 15:00:00 +10:00
return this.unmodifiableMobCategoryCounts;
2020-06-25 10:00:00 +10:00
}
2024-10-23 02:15:00 +11:00
- boolean canSpawnForCategoryGlobal(EnumCreatureType enumcreaturetype) {
2021-11-22 09:00:00 +11:00
- int i = enumcreaturetype.getMaxInstancesPerChunk() * this.spawnableChunkCount / SpawnerCreature.MAGIC_NUMBER;
2020-06-25 10:00:00 +10:00
+ // CraftBukkit start
2024-10-23 02:15:00 +11:00
+ boolean canSpawnForCategoryGlobal(EnumCreatureType enumcreaturetype, 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
2024-10-23 02:15:00 +11:00
return this.mobCategoryCounts.getInt(enumcreaturetype) < i;
2020-06-25 10:00:00 +10:00
}