| 1 | package net.minecraft.world.entity.boss.enderdragon.phases;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.core.particles.ParticleTypes;
|
| 5 | import net.minecraft.core.particles.PowerParticleOption;
|
| 6 | import net.minecraft.server.level.ServerLevel;
|
| 7 | import net.minecraft.util.Mth;
|
| 8 | import net.minecraft.world.effect.MobEffectInstance;
|
| 9 | import net.minecraft.world.effect.MobEffects;
|
| 10 | import net.minecraft.world.entity.AreaEffectCloud;
|
| 11 | import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
|
| 12 | import net.minecraft.world.phys.Vec3;
|
| 13 | import org.jspecify.annotations.Nullable;
|
| 14 |
|
| 15 | public class DragonSittingFlamingPhase extends AbstractDragonSittingPhase {
|
| 16 | private static final int FLAME_DURATION = 200;
|
| 17 | private static final int SITTING_FLAME_ATTACKS_COUNT = 4;
|
| 18 | private static final int WARMUP_TIME = 10;
|
| 19 | private int flameTicks;
|
| 20 | private int flameCount;
|
| 21 | private @Nullable AreaEffectCloud flame;
|
| 22 |
|
| 23 | public DragonSittingFlamingPhase(final EnderDragon dragon) {
|
| 24 | super(dragon);
|
| 25 | }
|
| 26 |
|
| 27 | @Override
|
| 28 | public void doClientTick() {
|
| 29 | this.flameTicks++;
|
| 30 | if (this.flameTicks % 2 == 0 && this.flameTicks < 10) {
|
| 31 | Vec3 look = this.dragon.getHeadLookVector(1.0F).normalize();
|
| 32 | look.yRot((float) (-Math.PI / 4));
|
| 33 | double particleX = this.dragon.head.getX();
|
| 34 | double particleY = this.dragon.head.getY(0.5);
|
| 35 | double particleZ = this.dragon.head.getZ();
|
| 36 |
|
| 37 | for (int i = 0; i < 8; i++) {
|
| 38 | double px = particleX + this.dragon.getRandom().nextGaussian() / 2.0;
|
| 39 | double py = particleY + this.dragon.getRandom().nextGaussian() / 2.0;
|
| 40 | double pz = particleZ + this.dragon.getRandom().nextGaussian() / 2.0;
|
| 41 |
|
| 42 | for (int j = 0; j < 6; j++) {
|
| 43 | this.dragon
|
| 44 | .level()
|
| 45 | .addParticle(PowerParticleOption.create(ParticleTypes.DRAGON_BREATH, 1.0F), px, py, pz, -look.x * 0.08F * j, -look.y * 0.6F, -look.z * 0.08F * j);
|
| 46 | }
|
| 47 |
|
| 48 | look.yRot((float) (Math.PI / 16));
|
| 49 | }
|
| 50 | }
|
| 51 | }
|
| 52 |
|
| 53 | @Override
|
| 54 | public void doServerTick(final ServerLevel level) {
|
| 55 | this.flameTicks++;
|
| 56 | if (this.flameTicks >= 200) {
|
| 57 | if (this.flameCount >= 4) {
|
| 58 | this.dragon.getPhaseManager().setPhase(EnderDragonPhase.TAKEOFF);
|
| 59 | } else {
|
| 60 | this.dragon.getPhaseManager().setPhase(EnderDragonPhase.SITTING_SCANNING);
|
| 61 | }
|
| 62 | } else if (this.flameTicks == 10) {
|
| 63 | Vec3 look = new Vec3(this.dragon.head.getX() - this.dragon.getX(), 0.0, this.dragon.head.getZ() - this.dragon.getZ()).normalize();
|
| 64 | float radius = 5.0F;
|
| 65 | double x = this.dragon.head.getX() + look.x * 5.0 / 2.0;
|
| 66 | double z = this.dragon.head.getZ() + look.z * 5.0 / 2.0;
|
| 67 | double initialY = this.dragon.head.getY(0.5);
|
| 68 | double y = initialY;
|
| 69 | BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(x, y, z);
|
| 70 |
|
| 71 | while (level.isEmptyBlock(pos)) {
|
| 72 | if (--y < 0.0) {
|
| 73 | y = initialY;
|
| 74 | break;
|
| 75 | }
|
| 76 |
|
| 77 | pos.set(x, y, z);
|
| 78 | }
|
| 79 |
|
| 80 | y = Mth.floor(y) + 1;
|
| 81 | this.flame = new AreaEffectCloud(level, x, y, z);
|
| 82 | this.flame.setOwner(this.dragon);
|
| 83 | this.flame.setRadius(5.0F);
|
| 84 | this.flame.setDuration(200);
|
| 85 | this.flame.setCustomParticle(PowerParticleOption.create(ParticleTypes.DRAGON_BREATH, 1.0F));
|
| 86 | this.flame.setPotionDurationScale(0.25F);
|
| 87 | this.flame.addEffect(new MobEffectInstance(MobEffects.INSTANT_DAMAGE));
|
| 88 | level.addFreshEntity(this.flame);
|
| 89 | }
|
| 90 | }
|
| 91 |
|
| 92 | @Override
|
| 93 | public void begin() {
|
| 94 | this.flameTicks = 0;
|
| 95 | this.flameCount++;
|
| 96 | }
|
| 97 |
|
| 98 | @Override
|
| 99 | public void end() {
|
| 100 | if (this.flame != null) {
|
| 101 | this.flame.discard();
|
| 102 | this.flame = null;
|
| 103 | }
|
| 104 | }
|
| 105 |
|
| 106 | @Override
|
| 107 | public EnderDragonPhase<DragonSittingFlamingPhase> getPhase() {
|
| 108 | return EnderDragonPhase.SITTING_FLAMING;
|
| 109 | }
|
| 110 |
|
| 111 | public void resetFlameCount() {
|
| 112 | this.flameCount = 0;
|
| 113 | }
|
| 114 | }
|
| 115 |
|