90 lines
3.5 KiB
Java
90 lines
3.5 KiB
Java
package net.minecraft.world.level.levelgen;
|
|
|
|
import net.minecraft.world.entity.SpawnGroupData;
|
|
import net.minecraft.world.level.material.FluidState;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.stats.ServerStatsCounter;
|
|
import net.minecraft.world.DifficultyInstance;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import java.util.Iterator;
|
|
import java.util.Random;
|
|
import net.minecraft.nbt.CompoundTag;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.world.entity.MobSpawnType;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.entity.EntityType;
|
|
import net.minecraft.world.entity.monster.Phantom;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.NaturalSpawner;
|
|
import net.minecraft.util.Mth;
|
|
import net.minecraft.stats.Stat;
|
|
import net.minecraft.stats.Stats;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
import net.minecraft.world.level.GameRules;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
|
|
public class PhantomSpawner {
|
|
private int nextTick;
|
|
|
|
public int tick(final ServerLevel xd, final boolean boolean2, final boolean boolean3) {
|
|
if (!boolean2) {
|
|
return 0;
|
|
}
|
|
if (!xd.getGameRules().getBoolean(GameRules.RULE_DOINSOMNIA)) {
|
|
return 0;
|
|
}
|
|
final Random random5 = xd.random;
|
|
--this.nextTick;
|
|
if (this.nextTick > 0) {
|
|
return 0;
|
|
}
|
|
this.nextTick += (60 + random5.nextInt(60)) * 20;
|
|
if (xd.getSkyDarken() < 5 && xd.dimension.isHasSkyLight()) {
|
|
return 0;
|
|
}
|
|
int integer6 = 0;
|
|
for (final Player ayg8 : xd.players()) {
|
|
if (ayg8.isSpectator()) {
|
|
continue;
|
|
}
|
|
final BlockPos fk9 = new BlockPos(ayg8);
|
|
if (xd.dimension.isHasSkyLight()) {
|
|
if (fk9.getY() < xd.getSeaLevel()) {
|
|
continue;
|
|
}
|
|
if (!xd.canSeeSky(fk9)) {
|
|
continue;
|
|
}
|
|
}
|
|
final DifficultyInstance ajg10 = xd.getCurrentDifficultyAt(fk9);
|
|
if (!ajg10.isHarderThan(random5.nextFloat() * 3.0f)) {
|
|
continue;
|
|
}
|
|
final ServerStatsCounter aan11 = ((ServerPlayer)ayg8).getStats();
|
|
final int integer7 = Mth.clamp(aan11.getValue(Stats.CUSTOM.get(Stats.TIME_SINCE_REST)), 1, Integer.MAX_VALUE);
|
|
final int integer8 = 24000;
|
|
if (random5.nextInt(integer7) < 72000) {
|
|
continue;
|
|
}
|
|
final BlockPos fk10 = fk9.above(20 + random5.nextInt(15)).east(-10 + random5.nextInt(21)).south(-10 + random5.nextInt(21));
|
|
final BlockState byg15 = xd.getBlockState(fk10);
|
|
final FluidState cog16 = xd.getFluidState(fk10);
|
|
if (!NaturalSpawner.isValidEmptySpawnBlock(xd, fk10, byg15, cog16)) {
|
|
continue;
|
|
}
|
|
SpawnGroupData alj17 = null;
|
|
final int integer9 = 1 + random5.nextInt(ajg10.getDifficulty().getId() + 1);
|
|
for (int integer10 = 0; integer10 < integer9; ++integer10) {
|
|
final Phantom awv20 = EntityType.PHANTOM.create(xd);
|
|
awv20.moveTo(fk10, 0.0f, 0.0f);
|
|
alj17 = awv20.finalizeSpawn(xd, ajg10, MobSpawnType.NATURAL, alj17, null);
|
|
xd.addFreshEntity(awv20);
|
|
}
|
|
integer6 += integer9;
|
|
}
|
|
return integer6;
|
|
}
|
|
}
|