1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791
| private void tickChunks() {
long l = this.world.getTime();
long m = l - this.lastMobSpawningTime;
this.lastMobSpawningTime = l;
boolean bl = this.world.isDebugWorld();
if (bl) {
this.threadedAnvilChunkStorage.tickEntityMovement();
} else {
WorldProperties lv = this.world.getLevelProperties();
Profiler lv2 = this.world.getProfiler();
lv2.push("pollingChunks");
int i = this.world.getGameRules().getInt(GameRules.RANDOM_TICK_SPEED);
boolean bl2 = lv.getTime() % 400L == 0L;
lv2.push("naturalSpawnCount");
int j = this.ticketManager.getTickedChunkCount();
SpawnHelper.Info lv3 = SpawnHelper.setupSpawn(j, this.world.iterateEntities(), this::ifChunkLoaded, new SpawnDensityCapper(this.threadedAnvilChunkStorage));
this.spawnInfo = lv3;
lv2.swap("filteringLoadedChunks");
List<ChunkWithHolder> list = Lists.newArrayListWithCapacity(j);
for(ChunkHolder lv4 : this.threadedAnvilChunkStorage.entryIterator()) {
WorldChunk lv5 = lv4.getWorldChunk();
if (lv5 != null) {
list.add(new ChunkWithHolder(lv5, lv4));
}
}
lv2.swap("spawnAndTick");
boolean bl3 = this.world.getGameRules().getBoolean(GameRules.DO_MOB_SPAWNING);
Collections.shuffle(list);
for(ChunkWithHolder lv6 : list) {
WorldChunk lv7 = lv6.chunk;
ChunkPos lv8 = lv7.getPos();
if (this.world.shouldTick(lv8) && this.threadedAnvilChunkStorage.shouldTick(lv8)) {
lv7.increaseInhabitedTime(m);
if (bl3 && (this.spawnMonsters || this.spawnAnimals) && this.world.getWorldBorder().contains(lv8)) {
SpawnHelper.spawn(this.world, lv7, lv3, this.spawnAnimals, this.spawnMonsters, bl2);
}
if (this.world.shouldTickBlocksInChunk(lv8.toLong())) {
this.world.tickChunk(lv7, i);
}
}
}
lv2.swap("customSpawners");
if (bl3) {
this.world.tickSpawners(this.spawnMonsters, this.spawnAnimals);
}
lv2.swap("broadcast");
list.forEach((chunk) -> chunk.holder.flushUpdates(chunk.chunk));
lv2.pop();
lv2.pop();
this.threadedAnvilChunkStorage.tickEntityMovement();
}
}
public static void spawn(ServerWorld world, WorldChunk chunk, Info info, boolean spawnAnimals, boolean spawnMonsters, boolean rareSpawn) {
world.getProfiler().push("spawner");
for(SpawnGroup lv : SPAWNABLE_GROUPS) {
if ((spawnAnimals || !lv.isPeaceful()) && (spawnMonsters || lv.isPeaceful()) && (rareSpawn || !lv.isRare()) && info.isBelowCap(lv, chunk.getPos())) {
Objects.requireNonNull(info);
Checker var10003 = info::test;
Objects.requireNonNull(info);
spawnEntitiesInChunk(lv, world, chunk, var10003, info::run);
}
}
world.getProfiler().pop();
}
private static BlockPos getRandomPosInChunkSection(World world, WorldChunk chunk) {
ChunkPos lv = chunk.getPos();
int i = lv.getStartX() + world.random.nextInt(16);
int j = lv.getStartZ() + world.random.nextInt(16);
int k = chunk.sampleHeightmap(Type.WORLD_SURFACE, i, j) + 1;
int l = MathHelper.nextBetween(world.random, world.getBottomY(), k);
return new BlockPos(i, l, j);
}
public static void spawnEntitiesInChunk(SpawnGroup group, ServerWorld world, WorldChunk chunk, Checker checker, Runner runner) {
BlockPos lv = getRandomPosInChunkSection(world, chunk);
if (lv.getY() >= world.getBottomY() + 1) {
spawnEntitiesInChunk(group, world, chunk, lv, checker, runner);
}
}
@Debug
public static void spawnEntitiesInChunk(SpawnGroup group, ServerWorld world, BlockPos pos) {
spawnEntitiesInChunk(group, world, world.getChunk(pos), pos, (type, posx, chunk) -> true, (entity, chunk) -> {
});
}
public static void spawnEntitiesInChunk(SpawnGroup group, ServerWorld world, Chunk chunk, BlockPos pos, Checker checker, Runner runner) {
StructureAccessor lv = world.getStructureAccessor();
ChunkGenerator lv2 = world.getChunkManager().getChunkGenerator();
int i = pos.getY();
BlockState lv3 = chunk.getBlockState(pos);
if (!lv3.isSolidBlock(chunk, pos)) {
BlockPos.Mutable lv4 = new BlockPos.Mutable();
int j = 0;
for(int k = 0; k < 3; ++k) {
int l = pos.getX();
int m = pos.getZ();
int n = 6;
SpawnSettings.SpawnEntry lv5 = null;
EntityData lv6 = null;
int o = MathHelper.ceil(world.random.nextFloat() * 4.0F);
int p = 0;
for(int q = 0; q < o; ++q) {
l += world.random.nextInt(6) - world.random.nextInt(6);
m += world.random.nextInt(6) - world.random.nextInt(6);
lv4.set(l, i, m);
double d = (double)l + (double)0.5F;
double e = (double)m + (double)0.5F;
PlayerEntity lv7 = world.getClosestPlayer(d, (double)i, e, (double)-1.0F, false);
if (lv7 != null) {
double f = lv7.squaredDistanceTo(d, (double)i, e);
if (isAcceptableSpawnPosition(world, chunk, lv4, f))
{
if (lv5 == null) {
Optional<SpawnSettings.SpawnEntry> optional = pickRandomSpawnEntry(world, lv, lv2, group, world.random, lv4);
if (optional.isEmpty()) {
break;
}
lv5 = (SpawnSettings.SpawnEntry)optional.get();
o = lv5.minGroupSize + world.random.nextInt(1 + lv5.maxGroupSize - lv5.minGroupSize);
}
if (canSpawn(world, group, lv, lv2, lv5, lv4, f) && checker.test(lv5.type, lv4, chunk)) {
MobEntity lv8 = createMob(world, lv5.type);
if (lv8 == null) {
return;
}
lv8.refreshPositionAndAngles(d, (double)i, e, world.random.nextFloat() * 360.0F, 0.0F);
if (isValidSpawn(world, lv8, f)) {
lv6 = lv8.initialize(world, world.getLocalDifficulty(lv8.getBlockPos()), SpawnReason.NATURAL, lv6, (NbtCompound)null);
++j;
++p;
world.spawnEntityAndPassengers(lv8);
runner.run(lv8, chunk);
if (j >= lv8.getLimitPerChunk()) {
return;
}
if (lv8.spawnsTooManyForEachTry(p)) {
break;
}
}
}
}
}
}
}
}
}
private static boolean isAcceptableSpawnPosition(ServerWorld world, Chunk chunk, BlockPos.Mutable pos, double squaredDistance) {
if (squaredDistance <= (double)576.0F) {
return false;
} else if (world.getSpawnPos().isWithinDistance(new Vec3d((double)pos.getX() + (double)0.5F, (double)pos.getY(), (double)pos.getZ() + (double)0.5F), (double)24.0F)) {
return false;
} else {
return Objects.equals(new ChunkPos(pos), chunk.getPos()) || world.shouldTick(pos);
}
}
private static boolean canSpawn(ServerWorld world, SpawnGroup group, StructureAccessor structureAccessor, ChunkGenerator chunkGenerator, SpawnSettings.SpawnEntry spawnEntry, BlockPos.Mutable pos, double squaredDistance) {
EntityType<?> lv = spawnEntry.type;
if (lv.getSpawnGroup() == SpawnGroup.MISC) {
return false;
} else if (!lv.isSpawnableFarFromPlayer() && squaredDistance > (double)(lv.getSpawnGroup().getImmediateDespawnRange() * lv.getSpawnGroup().getImmediateDespawnRange())) {
return false;
} else if (lv.isSummonable() && containsSpawnEntry(world, structureAccessor, chunkGenerator, group, spawnEntry, pos)) {
SpawnRestriction.Location lv2 = SpawnRestriction.getLocation(lv);
if (!canSpawn(lv2, world, pos, lv))
return false;
} else if (!SpawnRestriction.canSpawn(lv, world, SpawnReason.NATURAL, pos, world.random)) {
return false;
} else {
return world.isSpaceEmpty(lv.createSimpleBoundingBox((double)pos.getX() + (double)0.5F, (double)pos.getY(), (double)pos.getZ() + (double)0.5F));
}
} else {
return false;
}
}
private static boolean isValidSpawn(ServerWorld world, MobEntity entity, double squaredDistance) {
if (squaredDistance > (double)(entity.getType().getSpawnGroup().getImmediateDespawnRange() * entity.getType().getSpawnGroup().getImmediateDespawnRange()) && entity.canImmediatelyDespawn(squaredDistance)) {
return false;
} else {
return entity.canSpawn(world, SpawnReason.NATURAL) && entity.canSpawn(world);
}
}
public static boolean canSpawn(SpawnRestriction.Location location, WorldView world, BlockPos pos, @Nullable EntityType<?> entityType) {
if (location == Location.NO_RESTRICTIONS) {
return true;
} else if (entityType != null && world.getWorldBorder().contains(pos)) {
BlockState lv = world.getBlockState(pos);
FluidState lv2 = world.getFluidState(pos);
BlockPos lv3 = pos.up();
BlockPos lv4 = pos.down();
switch (location) {
case IN_WATER:
return lv2.isIn(FluidTags.WATER) && !world.getBlockState(lv3).isSolidBlock(world, lv3);
case IN_LAVA:
return lv2.isIn(FluidTags.LAVA);
case ON_GROUND:
default:
BlockState lv5 = world.getBlockState(lv4);
if (!lv5.allowsSpawning(world, lv4, entityType)) {
return false;
} else {
return isClearForSpawn(world, pos, lv, lv2, entityType) && isClearForSpawn(world, lv3, world.getBlockState(lv3), world.getFluidState(lv3), entityType);
}
}
} else {
return false;
}
}
public enum SpawnGroup implements StringIdentifiable {
MONSTER("monster", 70, false, false, 128),
CREATURE("creature", 10, true, true, 128),
AMBIENT("ambient", 15, true, false, 128),
AXOLOTLS("axolotls", 5, true, false, 128),
UNDERGROUND_WATER_CREATURE("underground_water_creature", 5, true, false, 128),
WATER_CREATURE("water_creature", 5, true, false, 128),
WATER_AMBIENT("water_ambient", 20, true, false, 64),
MISC("misc", -1, true, true, 128);
public static final Codec<SpawnGroup> CODEC = StringIdentifiable.createCodec(SpawnGroup::values);
private final int capacity;
private final boolean peaceful;
private final boolean rare;
private final String name;
private final int despawnStartRange = 32;
private final int immediateDespawnRange;
private SpawnGroup(String name, int spawnCap, boolean peaceful, boolean rare, int immediateDespawnRange) {
this.name = name;
this.capacity = spawnCap;
this.peaceful = peaceful;
this.rare = rare;
this.immediateDespawnRange = immediateDespawnRange;
}
public String getName() {
return this.name;
}
public String asString() {
return this.name;
}
public int getCapacity() {
return this.capacity;
}
public boolean isPeaceful() {
return this.peaceful;
}
public boolean isRare() {
return this.rare;
}
public int getImmediateDespawnRange() {
return this.immediateDespawnRange;
}
public int getDespawnStartRange() {
return 32;
}
}
public class SpawnRestriction {
private static final Map<EntityType<?>, Entry> RESTRICTIONS = Maps.newHashMap();
private static <T extends MobEntity> void register(EntityType<T> type, Location location, Heightmap.Type heightmapType, SpawnPredicate<T> predicate) {
Entry lv = (Entry)RESTRICTIONS.put(type, new Entry(heightmapType, location, predicate));
if (lv != null) {
throw new IllegalStateException("Duplicate registration for type " + Registries.ENTITY_TYPE.getId(type));
}
}
public static Location getLocation(EntityType<?> type) {
Entry lv = (Entry)RESTRICTIONS.get(type);
return lv == null ? SpawnRestriction.Location.NO_RESTRICTIONS : lv.location;
}
public static Heightmap.Type getHeightmapType(@Nullable EntityType<?> type) {
Entry lv = (Entry)RESTRICTIONS.get(type);
return lv == null ? Type.MOTION_BLOCKING_NO_LEAVES : lv.heightmapType;
}
public static <T extends Entity> boolean canSpawn(EntityType<T> type, ServerWorldAccess world, SpawnReason spawnReason, BlockPos pos, Random random) {
Entry lv = (Entry)RESTRICTIONS.get(type);
return lv == null || lv.predicate.test(type, world, spawnReason, pos, random);
}
static {
register(EntityType.AXOLOTL, SpawnRestriction.Location.IN_WATER, Type.MOTION_BLOCKING_NO_LEAVES, AxolotlEntity::canSpawn);
register(EntityType.COD, SpawnRestriction.Location.IN_WATER, Type.MOTION_BLOCKING_NO_LEAVES, WaterCreatureEntity::canSpawn);
register(EntityType.DOLPHIN, SpawnRestriction.Location.IN_WATER, Type.MOTION_BLOCKING_NO_LEAVES, WaterCreatureEntity::canSpawn);
register(EntityType.DROWNED, SpawnRestriction.Location.IN_WATER, Type.MOTION_BLOCKING_NO_LEAVES, DrownedEntity::canSpawn);
register(EntityType.GUARDIAN, SpawnRestriction.Location.IN_WATER, Type.MOTION_BLOCKING_NO_LEAVES, GuardianEntity::canSpawn);
register(EntityType.PUFFERFISH, SpawnRestriction.Location.IN_WATER, Type.MOTION_BLOCKING_NO_LEAVES, WaterCreatureEntity::canSpawn);
register(EntityType.SALMON, SpawnRestriction.Location.IN_WATER, Type.MOTION_BLOCKING_NO_LEAVES, WaterCreatureEntity::canSpawn);
register(EntityType.SQUID, SpawnRestriction.Location.IN_WATER, Type.MOTION_BLOCKING_NO_LEAVES, WaterCreatureEntity::canSpawn);
register(EntityType.TROPICAL_FISH, SpawnRestriction.Location.IN_WATER, Type.MOTION_BLOCKING_NO_LEAVES, TropicalFishEntity::canTropicalFishSpawn);
register(EntityType.BAT, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, BatEntity::canSpawn);
register(EntityType.BLAZE, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, HostileEntity::canSpawnIgnoreLightLevel);
register(EntityType.CAVE_SPIDER, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, HostileEntity::canSpawnInDark);
register(EntityType.CHICKEN, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, AnimalEntity::isValidNaturalSpawn);
register(EntityType.COW, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, AnimalEntity::isValidNaturalSpawn);
register(EntityType.CREEPER, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, HostileEntity::canSpawnInDark);
register(EntityType.DONKEY, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, AnimalEntity::isValidNaturalSpawn);
register(EntityType.ENDERMAN, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, HostileEntity::canSpawnInDark);
register(EntityType.ENDERMITE, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, EndermiteEntity::canSpawn);
register(EntityType.ENDER_DRAGON, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, MobEntity::canMobSpawn);
register(EntityType.FROG, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, FrogEntity::canSpawn);
register(EntityType.GHAST, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, GhastEntity::canSpawn);
register(EntityType.GIANT, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, HostileEntity::canSpawnInDark);
register(EntityType.GLOW_SQUID, SpawnRestriction.Location.IN_WATER, Type.MOTION_BLOCKING_NO_LEAVES, GlowSquidEntity::canSpawn);
register(EntityType.GOAT, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, GoatEntity::canSpawn);
register(EntityType.HORSE, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, AnimalEntity::isValidNaturalSpawn);
register(EntityType.HUSK, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, HuskEntity::canSpawn);
register(EntityType.IRON_GOLEM, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, MobEntity::canMobSpawn);
register(EntityType.LLAMA, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, AnimalEntity::isValidNaturalSpawn);
register(EntityType.MAGMA_CUBE, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, MagmaCubeEntity::canMagmaCubeSpawn);
register(EntityType.MOOSHROOM, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, MooshroomEntity::canSpawn);
register(EntityType.MULE, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, AnimalEntity::isValidNaturalSpawn);
register(EntityType.OCELOT, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING, OcelotEntity::canSpawn);
register(EntityType.PARROT, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING, ParrotEntity::canSpawn);
register(EntityType.PIG, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, AnimalEntity::isValidNaturalSpawn);
register(EntityType.HOGLIN, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, HoglinEntity::canSpawn);
register(EntityType.PIGLIN, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, PiglinEntity::canSpawn);
register(EntityType.PILLAGER, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, PatrolEntity::canSpawn);
register(EntityType.POLAR_BEAR, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, PolarBearEntity::canSpawn);
register(EntityType.RABBIT, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, RabbitEntity::canSpawn);
register(EntityType.SHEEP, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, AnimalEntity::isValidNaturalSpawn);
register(EntityType.SILVERFISH, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, SilverfishEntity::canSpawn);
register(EntityType.SKELETON, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, HostileEntity::canSpawnInDark);
register(EntityType.SKELETON_HORSE, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, AnimalEntity::isValidNaturalSpawn);
register(EntityType.SLIME, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, SlimeEntity::canSpawn);
register(EntityType.SNOW_GOLEM, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, MobEntity::canMobSpawn);
register(EntityType.SPIDER, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, HostileEntity::canSpawnInDark);
register(EntityType.STRAY, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, StrayEntity::canSpawn);
register(EntityType.STRIDER, SpawnRestriction.Location.IN_LAVA, Type.MOTION_BLOCKING_NO_LEAVES, StriderEntity::canSpawn);
register(EntityType.TURTLE, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, TurtleEntity::canSpawn);
register(EntityType.VILLAGER, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, MobEntity::canMobSpawn);
register(EntityType.WITCH, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, HostileEntity::canSpawnInDark);
register(EntityType.WITHER, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, HostileEntity::canSpawnInDark);
register(EntityType.WITHER_SKELETON, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, HostileEntity::canSpawnInDark);
register(EntityType.WOLF, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, WolfEntity::canSpawn);
register(EntityType.ZOMBIE, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, HostileEntity::canSpawnInDark);
register(EntityType.ZOMBIE_HORSE, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, AnimalEntity::isValidNaturalSpawn);
register(EntityType.ZOMBIFIED_PIGLIN, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, ZombifiedPiglinEntity::canSpawn);
register(EntityType.ZOMBIE_VILLAGER, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, HostileEntity::canSpawnInDark);
register(EntityType.CAT, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, AnimalEntity::isValidNaturalSpawn);
register(EntityType.ELDER_GUARDIAN, SpawnRestriction.Location.IN_WATER, Type.MOTION_BLOCKING_NO_LEAVES, GuardianEntity::canSpawn);
register(EntityType.EVOKER, SpawnRestriction.Location.NO_RESTRICTIONS, Type.MOTION_BLOCKING_NO_LEAVES, HostileEntity::canSpawnInDark);
register(EntityType.FOX, SpawnRestriction.Location.NO_RESTRICTIONS, Type.MOTION_BLOCKING_NO_LEAVES, FoxEntity::canSpawn);
register(EntityType.ILLUSIONER, SpawnRestriction.Location.NO_RESTRICTIONS, Type.MOTION_BLOCKING_NO_LEAVES, HostileEntity::canSpawnInDark);
register(EntityType.PANDA, SpawnRestriction.Location.NO_RESTRICTIONS, Type.MOTION_BLOCKING_NO_LEAVES, AnimalEntity::isValidNaturalSpawn);
register(EntityType.PHANTOM, SpawnRestriction.Location.NO_RESTRICTIONS, Type.MOTION_BLOCKING_NO_LEAVES, MobEntity::canMobSpawn);
register(EntityType.RAVAGER, SpawnRestriction.Location.NO_RESTRICTIONS, Type.MOTION_BLOCKING_NO_LEAVES, HostileEntity::canSpawnInDark);
register(EntityType.SHULKER, SpawnRestriction.Location.NO_RESTRICTIONS, Type.MOTION_BLOCKING_NO_LEAVES, MobEntity::canMobSpawn);
register(EntityType.TRADER_LLAMA, SpawnRestriction.Location.NO_RESTRICTIONS, Type.MOTION_BLOCKING_NO_LEAVES, AnimalEntity::isValidNaturalSpawn);
register(EntityType.VEX, SpawnRestriction.Location.NO_RESTRICTIONS, Type.MOTION_BLOCKING_NO_LEAVES, HostileEntity::canSpawnInDark);
register(EntityType.VINDICATOR, SpawnRestriction.Location.NO_RESTRICTIONS, Type.MOTION_BLOCKING_NO_LEAVES, HostileEntity::canSpawnInDark);
register(EntityType.WANDERING_TRADER, SpawnRestriction.Location.NO_RESTRICTIONS, Type.MOTION_BLOCKING_NO_LEAVES, MobEntity::canMobSpawn);
register(EntityType.WARDEN, SpawnRestriction.Location.NO_RESTRICTIONS, Type.MOTION_BLOCKING_NO_LEAVES, MobEntity::canMobSpawn);
}
static class Entry {
final Heightmap.Type heightmapType;
final Location location;
final SpawnPredicate<?> predicate;
public Entry(Heightmap.Type heightmapType, Location location, SpawnPredicate<?> predicate) {
this.heightmapType = heightmapType;
this.location = location;
this.predicate = predicate;
}
}
public static enum Location {
ON_GROUND,
IN_WATER,
NO_RESTRICTIONS,
IN_LAVA;
}
@FunctionalInterface
public interface SpawnPredicate<T extends Entity> {
boolean test(EntityType<T> type, ServerWorldAccess world, SpawnReason spawnReason, BlockPos pos, Random random);
}
}
register(EntityType.SLIME, SpawnRestriction.Location.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, SlimeEntity::canSpawn);
public static boolean canSpawn(EntityType<SlimeEntity> type, WorldAccess world, SpawnReason spawnReason, BlockPos pos, Random random) {
if (world.getDifficulty() != Difficulty.PEACEFUL) {
if (world.getBiome(pos).isIn(BiomeTags.ALLOWS_SURFACE_SLIME_SPAWNS) && pos.getY() > 50 && pos.getY() < 70 && random.nextFloat() < 0.5F && random.nextFloat() < world.getMoonSize() && world.getLightLevel(pos) <= random.nextInt(8)) {
return canMobSpawn(type, world, spawnReason, pos, random);
}
if (!(world instanceof StructureWorldAccess)) {
return false;
}
ChunkPos lv = new ChunkPos(pos);
boolean bl = ChunkRandom.getSlimeRandom(lv.x, lv.z, ((StructureWorldAccess)world).getSeed(), 987234911L).nextInt(10) == 0;
if (random.nextInt(10) == 0 && bl && pos.getY() < 40) {
return canMobSpawn(type, world, spawnReason, pos, random);
}
}
return false;
}
|