use of net.minecraft.pathfinding.PathPoint in project NetherEx by LogicTechCorp.
the class EntityAIFenceGateInteract method shouldExecute.
@Override
public boolean shouldExecute() {
if (!theEntity.isCollidedHorizontally) {
return false;
} else {
PathNavigateGround pathnavigateground = (PathNavigateGround) theEntity.getNavigator();
Path path = pathnavigateground.getPath();
if (path != null && !path.isFinished() && pathnavigateground.getEnterDoors()) {
for (int i = 0; i < Math.min(path.getCurrentPathIndex() + 2, path.getCurrentPathLength()); ++i) {
PathPoint pathpoint = path.getPathPointFromIndex(i);
fenceGatePos = new BlockPos(pathpoint.xCoord, pathpoint.yCoord, pathpoint.zCoord);
if (theEntity.getDistanceSq((double) fenceGatePos.getX(), theEntity.posY, (double) fenceGatePos.getZ()) <= 2.25D) {
fenceGate = getFenceGate(fenceGatePos);
if (fenceGate != null) {
return true;
}
}
}
fenceGatePos = (new BlockPos(theEntity));
fenceGate = getFenceGate(fenceGatePos);
return fenceGate != null;
} else {
return false;
}
}
}
use of net.minecraft.pathfinding.PathPoint in project MorePlanets by SteveKunG.
the class WalkNodeProcessorMP method getStart.
@Override
public PathPoint getStart() {
int i;
if (this.getCanSwim() && this.entity.isInWater()) {
i = (int) this.entity.getEntityBoundingBox().minY;
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(MathHelper.floor(this.entity.posX), i, MathHelper.floor(this.entity.posZ));
for (Block block = this.blockaccess.getBlockState(blockpos$mutableblockpos).getBlock(); block == Blocks.FLOWING_WATER || block == Blocks.WATER || block instanceof BlockFluidBase; block = this.blockaccess.getBlockState(blockpos$mutableblockpos).getBlock()) {
++i;
blockpos$mutableblockpos.setPos(MathHelper.floor(this.entity.posX), i, MathHelper.floor(this.entity.posZ));
}
} else if (this.entity.onGround) {
i = MathHelper.floor(this.entity.getEntityBoundingBox().minY + 0.5D);
} else {
BlockPos blockpos;
for (blockpos = new BlockPos(this.entity); (this.blockaccess.getBlockState(blockpos).getMaterial() == Material.AIR || this.blockaccess.getBlockState(blockpos).getBlock().isPassable(this.blockaccess, blockpos)) && blockpos.getY() > 0; blockpos = blockpos.down()) {
}
i = blockpos.up().getY();
}
BlockPos blockpos2 = new BlockPos(this.entity);
PathNodeType pathnodetype1 = this.getPathNodeType(this.entity, blockpos2.getX(), i, blockpos2.getZ());
if (this.entity.getPathPriority(pathnodetype1) < 0.0F) {
Set<BlockPos> set = new HashSet<>();
set.add(new BlockPos(this.entity.getEntityBoundingBox().minX, i, this.entity.getEntityBoundingBox().minZ));
set.add(new BlockPos(this.entity.getEntityBoundingBox().minX, i, this.entity.getEntityBoundingBox().maxZ));
set.add(new BlockPos(this.entity.getEntityBoundingBox().maxX, i, this.entity.getEntityBoundingBox().minZ));
set.add(new BlockPos(this.entity.getEntityBoundingBox().maxX, i, this.entity.getEntityBoundingBox().maxZ));
for (BlockPos blockpos1 : set) {
PathNodeType pathnodetype = this.getPathNodeType(this.entity, blockpos1);
if (this.entity.getPathPriority(pathnodetype) >= 0.0F) {
return this.openPoint(blockpos1.getX(), blockpos1.getY(), blockpos1.getZ());
}
}
}
return this.openPoint(blockpos2.getX(), i, blockpos2.getZ());
}
use of net.minecraft.pathfinding.PathPoint in project minecolonies by Minecolonies.
the class EntityAIGateInteract method checkFenceGate.
/**
* Checks if the citizen is close enough to an existing fence gate.
*
* @param path the path through the fence.
* @return true if the gate can be passed
*/
private boolean checkFenceGate(@NotNull final Path path) {
final int maxLengthToCheck = Math.min(path.getCurrentPathIndex() + LENGTH_TO_CHECK, path.getCurrentPathLength());
for (int i = 0; i < maxLengthToCheck; ++i) {
final PathPoint pathpoint = path.getPathPointFromIndex(i);
for (int level = 0; level < HEIGHT_TO_CHECK; level++) {
this.gatePosition = new BlockPos(pathpoint.x, pathpoint.y + level, pathpoint.z);
if (this.theEntity.getDistanceSq((double) this.gatePosition.getX(), this.theEntity.posY, (double) this.gatePosition.getZ()) <= MIN_DISTANCE) {
this.gateBlock = this.getBlockFence(this.gatePosition);
if (this.gateBlock != null) {
return true;
}
}
}
}
this.gatePosition = (new BlockPos(this.theEntity)).up();
this.gateBlock = this.getBlockFence(this.gatePosition);
return this.gateBlock != null;
}
use of net.minecraft.pathfinding.PathPoint in project minecolonies by Minecolonies.
the class AbstractPathJob method finalizePath.
/**
* Generate the path to the target node.
*
* @param targetNode the node to path to.
* @return the path.
*/
@NotNull
private Path finalizePath(final Node targetNode) {
// Compute length of path, since we need to allocate an array. This is cheaper/faster than building a List
// and converting it. Yes, we have targetNode.steps, but I do not want to rely on that being accurate (I might
// fudge that value later on for cutoff purposes
int pathLength = 0;
@Nullable Node node = targetNode;
while (node.parent != null) {
++pathLength;
node = node.parent;
}
@NotNull final PathPoint[] points = new PathPoint[pathLength];
@Nullable Node nextInPath = null;
node = targetNode;
while (node.parent != null) {
if (debugDrawEnabled) {
addPathNodeToDebug(node);
}
--pathLength;
@NotNull final BlockPos pos = node.pos;
if (node.isSwimming()) {
// Not truly necessary but helps prevent them spinning in place at swimming nodes
pos.add(BLOCKPOS_DOWN);
}
@NotNull final PathPointExtended p = new PathPointExtended(pos);
// Climbing on a ladder?
if (nextInPath != null && onALadder(node, nextInPath, pos)) {
p.setOnLadder(true);
if (nextInPath.pos.getY() > pos.getY()) {
// We only care about facing if going up
// In the case of BlockVines (Which does not have EnumFacing) we have to check the metadata of the vines... bitwise...
setLadderFacing(world, pos, p);
}
} else if (onALadder(node.parent, node.parent, pos)) {
p.setOnLadder(true);
}
points[pathLength] = p;
nextInPath = node;
node = node.parent;
}
doDebugPrinting(points);
return new Path(points);
}
use of net.minecraft.pathfinding.PathPoint in project minecolonies by Minecolonies.
the class AbstractPathJob method doDebugPrinting.
/**
* Turns on debug printing.
*
* @param points the points to print.
*/
private void doDebugPrinting(@NotNull final PathPoint[] points) {
if (Configurations.pathfinding.pathfindingDebugVerbosity > DEBUG_VERBOSITY_NONE) {
Log.getLogger().info("Path found:");
for (@NotNull final PathPoint p : points) {
Log.getLogger().info(String.format("Step: [%d,%d,%d]", p.x, p.y, p.z));
}
Log.getLogger().info(String.format("Total Nodes Visited %d / %d", totalNodesVisited, totalNodesAdded));
}
}
Aggregations