| 1 | package net.minecraft.world.entity.ai.navigation;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.util.Mth;
|
| 5 | import net.minecraft.world.entity.Entity;
|
| 6 | import net.minecraft.world.entity.Mob;
|
| 7 | import net.minecraft.world.level.Level;
|
| 8 | import net.minecraft.world.level.pathfinder.FlyNodeEvaluator;
|
| 9 | import net.minecraft.world.level.pathfinder.Path;
|
| 10 | import net.minecraft.world.level.pathfinder.PathFinder;
|
| 11 | import net.minecraft.world.phys.Vec3;
|
| 12 |
|
| 13 | public class FlyingPathNavigation extends PathNavigation {
|
| 14 | public FlyingPathNavigation(final Mob mob, final Level level) {
|
| 15 | super(mob, level);
|
| 16 | }
|
| 17 |
|
| 18 | @Override
|
| 19 | protected PathFinder createPathFinder(final int maxVisitedNodes) {
|
| 20 | this.nodeEvaluator = new FlyNodeEvaluator();
|
| 21 | return new PathFinder(this.nodeEvaluator, maxVisitedNodes);
|
| 22 | }
|
| 23 |
|
| 24 | @Override
|
| 25 | protected boolean canMoveDirectly(final Vec3 startPos, final Vec3 stopPos) {
|
| 26 | return isClearForMovementBetween(this.mob, startPos, stopPos, true);
|
| 27 | }
|
| 28 |
|
| 29 | @Override
|
| 30 | protected boolean canUpdatePath() {
|
| 31 | return this.canFloat() && this.mob.isInLiquid() || !this.mob.isPassenger();
|
| 32 | }
|
| 33 |
|
| 34 | @Override
|
| 35 | protected Vec3 getTempMobPos() {
|
| 36 | return this.mob.position();
|
| 37 | }
|
| 38 |
|
| 39 | @Override
|
| 40 | public Path createPath(final Entity target, final int reachRange) {
|
| 41 | return this.createPath(target.blockPosition(), reachRange);
|
| 42 | }
|
| 43 |
|
| 44 | @Override
|
| 45 | public void tick() {
|
| 46 | this.tick++;
|
| 47 | if (this.hasDelayedRecomputation) {
|
| 48 | this.recomputePath();
|
| 49 | }
|
| 50 |
|
| 51 | if (!this.isDone()) {
|
| 52 | if (this.canUpdatePath()) {
|
| 53 | this.followThePath();
|
| 54 | } else if (this.path != null && !this.path.isDone()) {
|
| 55 | Vec3 pos = this.path.getNextEntityPos(this.mob);
|
| 56 | if (this.mob.getBlockX() == Mth.floor(pos.x) && this.mob.getBlockY() == Mth.floor(pos.y) && this.mob.getBlockZ() == Mth.floor(pos.z)) {
|
| 57 | this.path.advance();
|
| 58 | }
|
| 59 | }
|
| 60 |
|
| 61 | if (!this.isDone()) {
|
| 62 | Vec3 target = this.path.getNextEntityPos(this.mob);
|
| 63 | this.mob.getMoveControl().setWantedPosition(target.x, target.y, target.z, this.speedModifier);
|
| 64 | }
|
| 65 | }
|
| 66 | }
|
| 67 |
|
| 68 | @Override
|
| 69 | public boolean isStableDestination(final BlockPos pos) {
|
| 70 | return this.level.getBlockState(pos).entityCanStandOn(this.level, pos, this.mob);
|
| 71 | }
|
| 72 |
|
| 73 | @Override
|
| 74 | public boolean canNavigateGround() {
|
| 75 | return false;
|
| 76 | }
|
| 77 | }
|
| 78 |
|