Search in sources :

Example 1 with GroundPathNavigator

use of net.minecraft.pathfinding.GroundPathNavigator in project minecolonies by ldtteam.

the class EntityAIInteractToggleAble method checkPathBlocksBelow.

/**
 * Checks the path for toggleables below, where we need to go through
 *
 * @return true if there is a toggleable block below us we need to go through
 */
private boolean checkPathBlocksBelow() {
    @NotNull final GroundPathNavigator pathnavigateground = (GroundPathNavigator) this.entity.getNavigation();
    final Path path = pathnavigateground.getPath();
    if (path == null || path.isDone()) {
        resetAll();
        return false;
    }
    final int maxLengthToCheck = Math.min(path.getNextNodeIndex() + LENGTH_TO_CHECK, path.getNodeCount());
    for (int i = Math.max(0, path.getNextNodeIndex() - 1); i < maxLengthToCheck; ++i) {
        final PathPoint pathpoint = path.getNode(i);
        for (int level = 0; level < getHeightToCheck(path, i); level++) {
            BlockPos pos = new BlockPos(pathpoint.x, pathpoint.y + level, pathpoint.z);
            // We only allows blocks we're on or right above
            if (!entity.blockPosition().equals(pos) && !entity.blockPosition().below().equals(pos)) {
                continue;
            }
            BlockState state = entity.level.getBlockState(pos);
            if (this.entity.distanceToSqr(pos.getX(), entity.getY(), pos.getZ()) <= MIN_DISTANCE && isValidBlockState(state)) {
                if (level > 0) {
                    // Above current pathing node, so need to use this toggleable block
                    toggleAblePositions.put(pos, entity.level.getBlockState(pos).getValue(BlockStateProperties.OPEN));
                } else if (i < path.getNodeCount() - 1) {
                    // Check if the next pathing node is below
                    final PathPoint nextPoint = path.getNode(i + 1);
                    if (pos.getX() == nextPoint.x && pos.getY() > nextPoint.y && pos.getZ() == nextPoint.z) {
                        toggleAblePositions.put(pos, entity.level.getBlockState(pos).getValue(BlockStateProperties.OPEN));
                    }
                }
            }
        }
    }
    return !toggleAblePositions.isEmpty();
}
Also used : Path(net.minecraft.pathfinding.Path) PathPoint(net.minecraft.pathfinding.PathPoint) GroundPathNavigator(net.minecraft.pathfinding.GroundPathNavigator) BlockPos(net.minecraft.util.math.BlockPos) NotNull(org.jetbrains.annotations.NotNull) PathPoint(net.minecraft.pathfinding.PathPoint)

Example 2 with GroundPathNavigator

use of net.minecraft.pathfinding.GroundPathNavigator in project Vampirism by TeamLapen.

the class AttackMeleeNoSunGoal method canUse.

@Override
public boolean canUse() {
    boolean flag = super.canUse();
    if (flag) {
        LivingEntity entitylivingbase = this.mob.getTarget();
        if (entitylivingbase != null) {
            double distance = this.mob.distanceToSqr(entitylivingbase.getX(), entitylivingbase.getBoundingBox().minY, entitylivingbase.getZ());
            if (distance <= this.getAttackReachSqr(entitylivingbase)) {
                return true;
            }
        }
        boolean avoidSun = false;
        if (mob.getNavigation() instanceof GroundPathNavigator) {
            avoidSun = ((GroundPathNavigator) mob.getNavigation()).avoidSun;
        }
        if (avoidSun) {
            Path path = this.path;
            if (mob.getCommandSenderWorld().canSeeSkyFromBelowWater(new BlockPos(MathHelper.floor(this.mob.getX()), (int) (this.mob.getBoundingBox().minY + 0.5D), MathHelper.floor(this.mob.getZ())))) {
                return false;
            }
            for (int j = 0; j < path.getNodeCount(); ++j) {
                PathPoint pathpoint2 = path.getNode(j);
                if (this.mob.getCommandSenderWorld().canSeeSkyFromBelowWater(new BlockPos(pathpoint2.x, pathpoint2.y, pathpoint2.z))) {
                    path.truncateNodes(Math.max(j - 1, 0));
                    return path.getNodeCount() > 1;
                }
            }
        }
    }
    return flag;
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) Path(net.minecraft.pathfinding.Path) PathPoint(net.minecraft.pathfinding.PathPoint) GroundPathNavigator(net.minecraft.pathfinding.GroundPathNavigator) BlockPos(net.minecraft.util.math.BlockPos) PathPoint(net.minecraft.pathfinding.PathPoint)

Example 3 with GroundPathNavigator

use of net.minecraft.pathfinding.GroundPathNavigator in project minecolonies by Minecolonies.

the class EntityAIInteractToggleAble method checkPath.

/**
 * Checks if there exists a path.
 *
 * @return true if the fence gate can be passed.
 */
private boolean checkPath() {
    @NotNull final GroundPathNavigator pathnavigateground = (GroundPathNavigator) this.entity.getNavigation();
    final Path path = pathnavigateground.getPath();
    checkPathBlocksCollided(path);
    return !toggleAblePositions.isEmpty();
}
Also used : Path(net.minecraft.pathfinding.Path) GroundPathNavigator(net.minecraft.pathfinding.GroundPathNavigator) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with GroundPathNavigator

use of net.minecraft.pathfinding.GroundPathNavigator in project minecolonies by Minecolonies.

the class EntityAIInteractToggleAble method checkPathBlocksBelow.

/**
 * Checks the path for toggleables below, where we need to go through
 *
 * @return true if there is a toggleable block below us we need to go through
 */
private boolean checkPathBlocksBelow() {
    @NotNull final GroundPathNavigator pathnavigateground = (GroundPathNavigator) this.entity.getNavigation();
    final Path path = pathnavigateground.getPath();
    if (path == null || path.isDone()) {
        resetAll();
        return false;
    }
    final int maxLengthToCheck = Math.min(path.getNextNodeIndex() + LENGTH_TO_CHECK, path.getNodeCount());
    for (int i = Math.max(0, path.getNextNodeIndex() - 1); i < maxLengthToCheck; ++i) {
        final PathPoint pathpoint = path.getNode(i);
        for (int level = 0; level < getHeightToCheck(path, i); level++) {
            BlockPos pos = new BlockPos(pathpoint.x, pathpoint.y + level, pathpoint.z);
            // We only allows blocks we're on or right above
            if (!entity.blockPosition().equals(pos) && !entity.blockPosition().below().equals(pos)) {
                continue;
            }
            BlockState state = entity.level.getBlockState(pos);
            if (this.entity.distanceToSqr(pos.getX(), entity.getY(), pos.getZ()) <= MIN_DISTANCE && isValidBlockState(state)) {
                if (level > 0) {
                    // Above current pathing node, so need to use this toggleable block
                    toggleAblePositions.put(pos, entity.level.getBlockState(pos).getValue(BlockStateProperties.OPEN));
                } else if (i < path.getNodeCount() - 1) {
                    // Check if the next pathing node is below
                    final PathPoint nextPoint = path.getNode(i + 1);
                    if (pos.getX() == nextPoint.x && pos.getY() > nextPoint.y && pos.getZ() == nextPoint.z) {
                        toggleAblePositions.put(pos, entity.level.getBlockState(pos).getValue(BlockStateProperties.OPEN));
                    }
                }
            }
        }
    }
    return !toggleAblePositions.isEmpty();
}
Also used : Path(net.minecraft.pathfinding.Path) PathPoint(net.minecraft.pathfinding.PathPoint) GroundPathNavigator(net.minecraft.pathfinding.GroundPathNavigator) BlockPos(net.minecraft.util.math.BlockPos) NotNull(org.jetbrains.annotations.NotNull) PathPoint(net.minecraft.pathfinding.PathPoint)

Example 5 with GroundPathNavigator

use of net.minecraft.pathfinding.GroundPathNavigator in project bioplethora by AquexTheSeal.

the class WaterAndLandAnimalEntity method switchNavigator.

public void switchNavigator(boolean onLand) {
    if (onLand) {
        this.moveControl = new MovementController(this);
        this.navigation = new GroundPathNavigator(this, level);
        this.isLandNavigator = true;
    } else {
        this.moveControl = new WaterMoveController(this, 1.2F);
        this.navigation = new WaterAndLandPathNavigator(this, level);
        this.isLandNavigator = false;
    }
}
Also used : GroundPathNavigator(net.minecraft.pathfinding.GroundPathNavigator) MovementController(net.minecraft.entity.ai.controller.MovementController) WaterAndLandPathNavigator(io.github.bioplethora.entity.ai.navigator.WaterAndLandPathNavigator) WaterMoveController(io.github.bioplethora.entity.ai.controller.WaterMoveController)

Aggregations

GroundPathNavigator (net.minecraft.pathfinding.GroundPathNavigator)9 Path (net.minecraft.pathfinding.Path)5 NotNull (org.jetbrains.annotations.NotNull)4 PathPoint (net.minecraft.pathfinding.PathPoint)3 BlockPos (net.minecraft.util.math.BlockPos)3 WaterMoveController (io.github.bioplethora.entity.ai.controller.WaterMoveController)2 WaterAndLandPathNavigator (io.github.bioplethora.entity.ai.navigator.WaterAndLandPathNavigator)2 LivingEntity (net.minecraft.entity.LivingEntity)2 Set (java.util.Set)1 MobEntity (net.minecraft.entity.MobEntity)1 MovementController (net.minecraft.entity.ai.controller.MovementController)1 FleeSunGoal (net.minecraft.entity.ai.goal.FleeSunGoal)1 Goal (net.minecraft.entity.ai.goal.Goal)1 PrioritizedGoal (net.minecraft.entity.ai.goal.PrioritizedGoal)1 RestrictSunGoal (net.minecraft.entity.ai.goal.RestrictSunGoal)1 PathNavigator (net.minecraft.pathfinding.PathNavigator)1 EffectInstance (net.minecraft.potion.EffectInstance)1 IHasTextureOverride (team.cqr.cqrepoured.customtextures.IHasTextureOverride)1 PathNavigateGroundCQR (team.cqr.cqrepoured.entity.pathfinding.PathNavigateGroundCQR)1