Search in sources :

Example 21 with Node

use of net.minecraft.world.level.pathfinder.Node in project Citizens2 by CitizensDev.

the class PlayerNodeEvaluator method getStart.

@Override
public Node getStart() {
    BlockPos.MutableBlockPos var1 = new BlockPos.MutableBlockPos();
    int var0 = this.mob.getBlockY();
    BlockState var2 = this.level.getBlockState(var1.set(this.mob.getX(), var0, this.mob.getZ()));
    if (this.mob.canStandOnFluid(var2.getFluidState().getType())) {
        while (this.mob.canStandOnFluid(var2.getFluidState().getType())) {
            var0++;
            var2 = this.level.getBlockState(var1.set(this.mob.getX(), var0, this.mob.getZ()));
        }
        var0--;
    } else if (canFloat() && this.mob.isInWater()) {
        while (var2.is(Blocks.WATER) || var2.getFluidState() == Fluids.WATER.getSource(false)) {
            var0++;
            var2 = this.level.getBlockState(var1.set(this.mob.getX(), var0, this.mob.getZ()));
        }
        var0--;
    } else if (this.mob.isOnGround()) {
        var0 = Mth.floor(this.mob.getY() + 0.5D);
    } else {
        BlockPos blockPos = this.mob.blockPosition();
        while ((this.level.getBlockState(blockPos).isAir() || this.level.getBlockState(blockPos).isPathfindable(this.level, blockPos, PathComputationType.LAND)) && blockPos.getY() > this.mob.level.getMinBuildHeight()) blockPos = blockPos.down();
        var0 = blockPos.up().getY();
    }
    BlockPos var3 = this.mob.blockPosition();
    BlockPathTypes var4 = getCachedBlockType(this.mob, var3.getX(), var0, var3.getZ());
    if (this.mob.getPathfindingMalus(var4) < 0.0F) {
        AABB aABB = this.mob.getBoundingBox();
        if (hasPositiveMalus(var1.set(aABB.minX, var0, aABB.minZ)) || hasPositiveMalus(var1.set(aABB.minX, var0, aABB.maxZ)) || hasPositiveMalus(var1.set(aABB.maxX, var0, aABB.minZ)) || hasPositiveMalus(var1.set(aABB.maxX, var0, aABB.maxZ))) {
            Node var6 = getNode(var1);
            var6.type = getBlockPathType(this.mob, var6.asBlockPos());
            var6.costMalus = this.mob.getPathfindingMalus(var6.type);
            return var6;
        }
    }
    Node var5 = getNode(var3.getX(), var0, var3.getZ());
    var5.type = getBlockPathType(this.mob, var5.asBlockPos());
    var5.costMalus = this.mob.getPathfindingMalus(var5.type);
    return var5;
}
Also used : BlockPathTypes(net.minecraft.world.level.pathfinder.BlockPathTypes) BlockState(net.minecraft.world.level.block.state.BlockState) Node(net.minecraft.world.level.pathfinder.Node) BlockPos(net.minecraft.core.BlockPos) AABB(net.minecraft.world.phys.AABB)

Example 22 with Node

use of net.minecraft.world.level.pathfinder.Node in project AlexsMobs by Alex-the-666.

the class BoneSerpentNodeProcessor method getNode.

/**
 * Returns a mapped point or creates and adds one
 */
@Nullable
protected Node getNode(int x, int y, int z) {
    Node pathpoint = null;
    BlockPathTypes pathnodetype = this.getBlockPathType(this.mob.level, x, y, z);
    float f = this.mob.getPathfindingMalus(pathnodetype);
    if (f >= 0.0F) {
        pathpoint = super.getNode(x, y, z);
        pathpoint.type = pathnodetype;
        pathpoint.costMalus = Math.max(pathpoint.costMalus, f);
        if (this.level.getFluidState(new BlockPos(x, y, z)).isEmpty()) {
            pathpoint.costMalus += 8.0F;
        }
    }
    return pathnodetype == BlockPathTypes.OPEN ? pathpoint : pathpoint;
}
Also used : BlockPathTypes(net.minecraft.world.level.pathfinder.BlockPathTypes) Node(net.minecraft.world.level.pathfinder.Node) BlockPos(net.minecraft.core.BlockPos) Nullable(javax.annotation.Nullable)

Example 23 with Node

use of net.minecraft.world.level.pathfinder.Node in project AlexsMobs by Alex-the-666.

the class CapuchinAITargetBalloons method canEasilyReach.

/**
 * Checks to see if this entity can find a short path to the given target.
 */
private boolean canEasilyReach(LivingEntity target) {
    this.targetSearchDelay = 10 + this.monkey.getRandom().nextInt(5);
    Path path = this.monkey.getNavigation().createPath(target, 0);
    if (path == null) {
        return false;
    } else {
        Node pathpoint = path.getEndNode();
        if (pathpoint == null) {
            return false;
        } else {
            int i = pathpoint.x - Mth.floor(target.getX());
            int j = pathpoint.z - Mth.floor(target.getZ());
            return (double) (i * i + j * j) <= 2.25D;
        }
    }
}
Also used : Path(net.minecraft.world.level.pathfinder.Path) Node(net.minecraft.world.level.pathfinder.Node)

Example 24 with Node

use of net.minecraft.world.level.pathfinder.Node in project Atum2 by TeamMetallurgy.

the class OpenAnyDoorGoal method canUse.

@Override
public boolean canUse() {
    if (!this.mob.horizontalCollision) {
        return false;
    } else {
        PathNavigation pathNavigator = this.mob.getNavigation();
        Path path = pathNavigator.getPath();
        if (path != null && !path.isDone()) {
            for (int i = 0; i < Math.min(path.getNextNodeIndex() + 2, path.getNodeCount()); ++i) {
                Node pathPoint = path.getNode(i);
                this.doorPos = new BlockPos(pathPoint.x, pathPoint.y + 1, pathPoint.z);
                if (!(this.mob.distanceToSqr(this.doorPos.getX(), this.mob.getY(), this.doorPos.getZ()) > 2.25D)) {
                    this.hasDoor = canOpen(this.mob.level, this.doorPos);
                    if (this.hasDoor) {
                        return true;
                    }
                }
            }
            this.doorPos = this.mob.blockPosition().above();
            this.hasDoor = canOpen(this.mob.level, this.doorPos);
            return this.hasDoor;
        } else {
            return false;
        }
    }
}
Also used : Path(net.minecraft.world.level.pathfinder.Path) Node(net.minecraft.world.level.pathfinder.Node) PathNavigation(net.minecraft.world.entity.ai.navigation.PathNavigation) BlockPos(net.minecraft.core.BlockPos)

Aggregations

Node (net.minecraft.world.level.pathfinder.Node)24 BlockPos (net.minecraft.core.BlockPos)16 Path (net.minecraft.world.level.pathfinder.Path)14 BlockPathTypes (net.minecraft.world.level.pathfinder.BlockPathTypes)9 Mob (net.minecraft.world.entity.Mob)8 Lists (com.google.common.collect.Lists)6 List (java.util.List)6 Map (java.util.Map)6 Set (java.util.Set)6 Setting (net.citizensnpcs.Settings.Setting)6 BlockState (net.minecraft.world.level.block.state.BlockState)6 Target (net.minecraft.world.level.pathfinder.Target)6 AABB (net.minecraft.world.phys.AABB)6 PathNavigation (net.minecraft.world.entity.ai.navigation.PathNavigation)5 PathFinder (net.minecraft.world.level.pathfinder.PathFinder)5 Sets (com.google.common.collect.Sets)4 Comparator (java.util.Comparator)4 Optional (java.util.Optional)4 Function (java.util.function.Function)4 Collectors (java.util.stream.Collectors)4