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();
}
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;
}
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();
}
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();
}
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;
}
}
Aggregations