Add '/paper mobcaps' and '/paper playermobcaps'

Add commands to get the mobcaps for a world, as well as the mobcaps for
each player when per-player mob spawning is enabled.

Also has a hover text on each mob category listing what entity types are
in said category
This commit is contained in:
Jason Penilla
2021-08-16 01:31:54 -05:00
parent c593e8510e
commit b67ec825d2
6 changed files with 289 additions and 10 deletions

View File

@@ -62,7 +62,24 @@
list.add(enumcreaturetype);
}
}
@@ -164,9 +192,9 @@
@@ -144,6 +172,16 @@
gameprofilerfiller.pop();
}
+ // Paper start - Add mobcaps commands
+ public static int globalLimitForCategory(final ServerLevel level, final MobCategory category, final int spawnableChunkCount) {
+ final int categoryLimit = level.getWorld().getSpawnLimitUnsafe(CraftSpawnCategory.toBukkit(category));
+ if (categoryLimit < 1) {
+ return categoryLimit;
+ }
+ return categoryLimit * spawnableChunkCount / NaturalSpawner.MAGIC_NUMBER;
+ }
+ // Paper end - Add mobcaps commands
+
public static void spawnCategoryForChunk(MobCategory group, ServerLevel world, LevelChunk chunk, NaturalSpawner.SpawnPredicate checker, NaturalSpawner.AfterSpawnCallback runner) {
BlockPos blockposition = NaturalSpawner.getRandomPosWithin(world, chunk);
@@ -164,9 +202,9 @@
StructureManager structuremanager = world.structureManager();
ChunkGenerator chunkgenerator = world.getChunkSource().getGenerator();
int i = pos.getY();
@@ -74,7 +91,7 @@
BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();
int j = 0;
int k = 0;
@@ -195,7 +223,7 @@
@@ -195,7 +233,7 @@
if (entityhuman != null) {
double d2 = entityhuman.distanceToSqr(d0, (double) i, d1);
@@ -83,7 +100,7 @@
if (biomesettingsmobs_c == null) {
Optional<MobSpawnSettings.SpawnerData> optional = NaturalSpawner.getRandomSpawnMobAt(world, structuremanager, chunkgenerator, group, world.random, blockposition_mutableblockposition);
@@ -207,7 +235,13 @@
@@ -207,7 +245,13 @@
j1 = biomesettingsmobs_c.minCount + world.random.nextInt(1 + biomesettingsmobs_c.maxCount - biomesettingsmobs_c.minCount);
}
@@ -98,7 +115,7 @@
Mob entityinsentient = NaturalSpawner.getMobForSpawn(world, biomesettingsmobs_c.type);
if (entityinsentient == null) {
@@ -217,10 +251,15 @@
@@ -217,10 +261,15 @@
entityinsentient.moveTo(d0, (double) i, d1, world.random.nextFloat() * 360.0F, 0.0F);
if (NaturalSpawner.isValidPositionForMob(world, entityinsentient, d2)) {
groupdataentity = entityinsentient.finalizeSpawn(world, world.getCurrentDifficultyAt(entityinsentient.blockPosition()), EntitySpawnReason.NATURAL, groupdataentity);
@@ -118,7 +135,7 @@
if (j >= entityinsentient.getMaxSpawnClusterSize()) {
return;
}
@@ -250,10 +289,31 @@
@@ -250,10 +299,31 @@
return squaredDistance <= 576.0D ? false : (world.getSharedSpawnPos().closerToCenterThan(new Vec3((double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D), 24.0D) ? false : Objects.equals(new ChunkPos(pos), chunk.getPos()) || world.isNaturalSpawningAllowed((BlockPos) pos));
}
@@ -152,7 +169,7 @@
}
@Nullable
@@ -268,6 +328,7 @@
@@ -268,6 +338,7 @@
NaturalSpawner.LOGGER.warn("Can't spawn entity of type: {}", BuiltInRegistries.ENTITY_TYPE.getKey(type));
} catch (Exception exception) {
NaturalSpawner.LOGGER.warn("Failed to create mob", exception);
@@ -160,7 +177,7 @@
}
return null;
@@ -356,6 +417,7 @@
@@ -356,6 +427,7 @@
entity = biomesettingsmobs_c.type.create(world.getLevel(), EntitySpawnReason.NATURAL);
} catch (Exception exception) {
NaturalSpawner.LOGGER.warn("Failed to create mob", exception);
@@ -168,7 +185,7 @@
continue;
}
@@ -369,7 +431,7 @@
@@ -369,7 +441,7 @@
if (entityinsentient.checkSpawnRules(world, EntitySpawnReason.CHUNK_GENERATION) && entityinsentient.checkSpawnObstruction(world)) {
groupdataentity = entityinsentient.finalizeSpawn(world, world.getCurrentDifficultyAt(entityinsentient.blockPosition()), EntitySpawnReason.CHUNK_GENERATION, groupdataentity);
@@ -177,7 +194,7 @@
flag = true;
}
}
@@ -482,10 +544,12 @@
@@ -482,10 +554,12 @@
return this.unmodifiableMobCategoryCounts;
}