| 1 | package net.minecraft.world.entity.ai.control;
|
| 2 |
|
| 3 | import net.minecraft.util.Mth;
|
| 4 | import net.minecraft.world.entity.Mob;
|
| 5 | import net.minecraft.world.entity.ai.attributes.Attributes;
|
| 6 |
|
| 7 | public class FlyingMoveControl<T extends Mob> extends MoveControl<T> {
|
| 8 | private final int maxTurn;
|
| 9 | private final boolean hoversInPlace;
|
| 10 |
|
| 11 | public FlyingMoveControl(final T mob, final int maxTurn, final boolean hoversInPlace) {
|
| 12 | super(mob);
|
| 13 | this.maxTurn = maxTurn;
|
| 14 | this.hoversInPlace = hoversInPlace;
|
| 15 | }
|
| 16 |
|
| 17 | @Override
|
| 18 | public void tick() {
|
| 19 | if (this.operation == MoveControl.Operation.MOVE_TO) {
|
| 20 | this.operation = MoveControl.Operation.WAIT;
|
| 21 | this.mob.setNoGravity(true);
|
| 22 | double xd = this.wantedX - this.mob.getX();
|
| 23 | double yd = this.wantedY - this.mob.getY();
|
| 24 | double zd = this.wantedZ - this.mob.getZ();
|
| 25 | double dd = xd * xd + yd * yd + zd * zd;
|
| 26 | if (dd < 2.5000003E-7F) {
|
| 27 | this.mob.setYya(0.0F);
|
| 28 | this.mob.setZza(0.0F);
|
| 29 | return;
|
| 30 | }
|
| 31 |
|
| 32 | float yRotD = (float)(Mth.atan2(zd, xd) * 180.0F / (float)Math.PI) - 90.0F;
|
| 33 | this.mob.setYRot(this.rotlerp(this.mob.getYRot(), yRotD, 90.0F));
|
| 34 | float speed;
|
| 35 | if (this.mob.onGround()) {
|
| 36 | speed = (float)(this.speedModifier * this.mob.getAttributeValue(Attributes.MOVEMENT_SPEED));
|
| 37 | } else {
|
| 38 | speed = (float)(this.speedModifier * this.mob.getAttributeValue(Attributes.FLYING_SPEED));
|
| 39 | }
|
| 40 |
|
| 41 | this.mob.setSpeed(speed);
|
| 42 | double sd = Math.sqrt(xd * xd + zd * zd);
|
| 43 | if (Math.abs(yd) > 1.0E-5F || Math.abs(sd) > 1.0E-5F) {
|
| 44 | float xRotD = (float)(-(Mth.atan2(yd, sd) * 180.0F / (float)Math.PI));
|
| 45 | this.mob.setXRot(this.rotlerp(this.mob.getXRot(), xRotD, this.maxTurn));
|
| 46 | this.mob.setYya(yd > 0.0 ? speed : -speed);
|
| 47 | }
|
| 48 | } else {
|
| 49 | if (!this.hoversInPlace) {
|
| 50 | this.mob.setNoGravity(false);
|
| 51 | }
|
| 52 |
|
| 53 | this.mob.setYya(0.0F);
|
| 54 | this.mob.setZza(0.0F);
|
| 55 | }
|
| 56 | }
|
| 57 | }
|
| 58 |
|