| 1 | package net.minecraft.world.entity.boss.enderdragon.phases;
|
| 2 |
|
| 3 | import net.minecraft.server.level.ServerLevel;
|
| 4 | import net.minecraft.util.Mth;
|
| 5 | import net.minecraft.world.entity.LivingEntity;
|
| 6 | import net.minecraft.world.entity.ai.targeting.TargetingConditions;
|
| 7 | import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
|
| 8 | import net.minecraft.world.phys.Vec3;
|
| 9 |
|
| 10 | public class DragonSittingScanningPhase extends AbstractDragonSittingPhase {
|
| 11 | private static final int SITTING_SCANNING_IDLE_TICKS = 100;
|
| 12 | private static final int SITTING_ATTACK_Y_VIEW_RANGE = 10;
|
| 13 | private static final int SITTING_ATTACK_VIEW_RANGE = 20;
|
| 14 | private static final int SITTING_CHARGE_VIEW_RANGE = 150;
|
| 15 | private static final TargetingConditions CHARGE_TARGETING = TargetingConditions.forCombat().range(150.0);
|
| 16 | private final TargetingConditions scanTargeting;
|
| 17 | private int scanningTime;
|
| 18 |
|
| 19 | public DragonSittingScanningPhase(final EnderDragon dragon) {
|
| 20 | super(dragon);
|
| 21 | this.scanTargeting = TargetingConditions.forCombat().range(20.0).selector((target, level) -> Math.abs(target.getY() - dragon.getY()) <= 10.0);
|
| 22 | }
|
| 23 |
|
| 24 | @Override
|
| 25 | public void doServerTick(final ServerLevel level) {
|
| 26 | this.scanningTime++;
|
| 27 | LivingEntity attackTarget = level.getNearestPlayer(this.scanTargeting, this.dragon, this.dragon.getX(), this.dragon.getY(), this.dragon.getZ());
|
| 28 | if (attackTarget != null) {
|
| 29 | if (this.scanningTime > 25) {
|
| 30 | this.dragon.getPhaseManager().setPhase(EnderDragonPhase.SITTING_ATTACKING);
|
| 31 | } else {
|
| 32 | Vec3 aim = new Vec3(attackTarget.getX() - this.dragon.getX(), 0.0, attackTarget.getZ() - this.dragon.getZ()).normalize();
|
| 33 | Vec3 dir = new Vec3(Mth.sin(this.dragon.getYRot() * (float) (Math.PI / 180.0)), 0.0, -Mth.cos(this.dragon.getYRot() * (float) (Math.PI / 180.0)))
|
| 34 | .normalize();
|
| 35 | float dot = (float)dir.dot(aim);
|
| 36 | float angle = (float)(Math.acos(dot) * 180.0F / (float)Math.PI) + 0.5F;
|
| 37 | if (angle < 0.0F || angle > 10.0F) {
|
| 38 | double xAttackDist = attackTarget.getX() - this.dragon.head.getX();
|
| 39 | double zAttackDist = attackTarget.getZ() - this.dragon.head.getZ();
|
| 40 | double yRotDelta = Mth.clamp(Mth.wrapDegrees(180.0 - Mth.atan2(xAttackDist, zAttackDist) * 180.0F / (float)Math.PI - this.dragon.getYRot()), -100.0, 100.0);
|
| 41 | this.dragon.yRotA *= 0.8F;
|
| 42 | float dist = (float)Math.sqrt(xAttackDist * xAttackDist + zAttackDist * zAttackDist) + 1.0F;
|
| 43 | float rotSpeed = dist;
|
| 44 | if (dist > 40.0F) {
|
| 45 | dist = 40.0F;
|
| 46 | }
|
| 47 |
|
| 48 | this.dragon.yRotA += (float)yRotDelta * (0.7F / dist / rotSpeed);
|
| 49 | this.dragon.setYRot(this.dragon.getYRot() + this.dragon.yRotA);
|
| 50 | }
|
| 51 | }
|
| 52 | } else if (this.scanningTime >= 100) {
|
| 53 | attackTarget = level.getNearestPlayer(CHARGE_TARGETING, this.dragon, this.dragon.getX(), this.dragon.getY(), this.dragon.getZ());
|
| 54 | this.dragon.getPhaseManager().setPhase(EnderDragonPhase.TAKEOFF);
|
| 55 | if (attackTarget != null) {
|
| 56 | this.dragon.getPhaseManager().setPhase(EnderDragonPhase.CHARGING_PLAYER);
|
| 57 | this.dragon.getPhaseManager().getPhase(EnderDragonPhase.CHARGING_PLAYER).setTarget(new Vec3(attackTarget.getX(), attackTarget.getY(), attackTarget.getZ()));
|
| 58 | }
|
| 59 | }
|
| 60 | }
|
| 61 |
|
| 62 | @Override
|
| 63 | public void begin() {
|
| 64 | this.scanningTime = 0;
|
| 65 | }
|
| 66 |
|
| 67 | @Override
|
| 68 | public EnderDragonPhase<DragonSittingScanningPhase> getPhase() {
|
| 69 | return EnderDragonPhase.SITTING_SCANNING;
|
| 70 | }
|
| 71 | }
|
| 72 |
|