net.minecraft.pathfinding.PathPoint Java Examples
The following examples show how to use
net.minecraft.pathfinding.PathPoint.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FlyingPathFinder.java From EnderZoo with Creative Commons Zero v1.0 Universal | 6 votes |
private static PathPoint[] createEntityPath(PathPoint start, PathPoint end) { int i = 1; for (PathPoint pathpoint = end; PPUtil.getPrevious(pathpoint) != null; pathpoint = PPUtil.getPrevious(pathpoint)) { ++i; } PathPoint[] apathpoint = new PathPoint[i]; PathPoint pathpoint1 = end; --i; for (apathpoint[i] = end; PPUtil.getPrevious(pathpoint1) != null; apathpoint[i] = pathpoint1) { pathpoint1 = PPUtil.getPrevious(pathpoint1); --i; } return apathpoint; }
Example #2
Source File: PPUtil.java From EnderZoo with Creative Commons Zero v1.0 Universal | 5 votes |
public static PathPoint getPrevious(PathPoint pp) { try { return (PathPoint) PREV.get(pp); } catch (Exception e) { throw new RuntimeException(e); } }
Example #3
Source File: EntityPathNavigateDrone.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
public PathEntity getEntityPathToXYZ(EntityDrone par1Entity, int par2, int par3, int par4, float par5, boolean par6, boolean par7, boolean par8, boolean par9){ if(!par1Entity.isBlockValidPathfindBlock(par2, par3, par4)) return null; PathEntity pathentity = null; int l = MathHelper.floor_double(par1Entity.posX); int i1 = MathHelper.floor_double(par1Entity.posY); int j1 = MathHelper.floor_double(par1Entity.posZ); if(!forceTeleport || l == par2 && i1 == par3 && j1 == par4) { int k1 = (int)(par5 + 8.0F); int l1 = l - k1; int i2 = i1 - k1; int j2 = j1 - k1; int k2 = l + k1; int l2 = i1 + k1; int i3 = j1 + k1; ChunkCache chunkcache = new ChunkCache(par1Entity.worldObj, l1, i2, j2, k2, l2, i3, 0); pathentity = new PathFinderDrone(par1Entity, chunkcache, par6, par7, pathThroughLiquid, par9).createEntityPathTo(par1Entity, par2, par3, par4, par5); if(pathentity != null) { PathPoint finalPoint = pathentity.getFinalPathPoint(); if(finalPoint == null || finalPoint.xCoord != par2 || finalPoint.yCoord != par3 || finalPoint.zCoord != par4) pathentity = null; } } teleportCounter = pathentity != null ? -1 : 0; telX = par2; telY = par3; telZ = par4; par1Entity.setStandby(false); return pathentity; }
Example #4
Source File: PPUtil.java From EnderZoo with Creative Commons Zero v1.0 Universal | 5 votes |
public static void setIndex(PathPoint pp, int i) { try { INDEX.setInt(pp, i); } catch (Exception e) { throw new RuntimeException(e); } }
Example #5
Source File: PPUtil.java From EnderZoo with Creative Commons Zero v1.0 Universal | 5 votes |
public static void setDistanceToTarget(PathPoint pp, float dist) { try { DIST_TO_TARG.setFloat(pp, dist); } catch (Exception e) { throw new RuntimeException(e); } }
Example #6
Source File: PPUtil.java From EnderZoo with Creative Commons Zero v1.0 Universal | 5 votes |
public static void setDistanceToNext(PathPoint pp, float dist) { try { DIST_TO_NEXT.setFloat(pp, dist); } catch (Exception e) { throw new RuntimeException(e); } }
Example #7
Source File: PPUtil.java From EnderZoo with Creative Commons Zero v1.0 Universal | 5 votes |
public static float getDistanceToNext(PathPoint pp) { try { return DIST_TO_NEXT.getFloat(pp); } catch (Exception e) { throw new RuntimeException(e); } }
Example #8
Source File: PPUtil.java From EnderZoo with Creative Commons Zero v1.0 Universal | 5 votes |
public static void setTotalPathDistance(PathPoint pp, float dist) { try { TOT_DIST.setFloat(pp, dist); } catch (Exception e) { throw new RuntimeException(e); } }
Example #9
Source File: PPUtil.java From EnderZoo with Creative Commons Zero v1.0 Universal | 5 votes |
public static float getTotalPathDistance(PathPoint pp) { try { return TOT_DIST.getFloat(pp); } catch (Exception e) { throw new RuntimeException(e); } }
Example #10
Source File: PPUtil.java From EnderZoo with Creative Commons Zero v1.0 Universal | 5 votes |
public static void setPrevious(PathPoint pp, PathPoint prev) { try { PREV.set(pp, prev); } catch (Exception e) { throw new RuntimeException(e); } }
Example #11
Source File: EntityAICustomDoorInteract.java From Et-Futurum with The Unlicense | 5 votes |
@Override public boolean shouldExecute() { if (!theEntity.isCollidedHorizontally) return false; else { PathNavigate pathnavigate = theEntity.getNavigator(); PathEntity pathentity = pathnavigate.getPath(); if (pathentity != null && !pathentity.isFinished() && pathnavigate.getCanBreakDoors()) { for (int i = 0; i < Math.min(pathentity.getCurrentPathIndex() + 2, pathentity.getCurrentPathLength()); ++i) { PathPoint pathpoint = pathentity.getPathPointFromIndex(i); entityPosX = pathpoint.xCoord; entityPosY = pathpoint.yCoord + 1; entityPosZ = pathpoint.zCoord; if (theEntity.getDistanceSq(entityPosX, theEntity.posY, entityPosZ) <= 2.25D) { field_151504_e = func_151503_a(entityPosX, entityPosY, entityPosZ); if (field_151504_e != null) return true; } } entityPosX = MathHelper.floor_double(theEntity.posX); entityPosY = MathHelper.floor_double(theEntity.posY + 1.0D); entityPosZ = MathHelper.floor_double(theEntity.posZ); field_151504_e = func_151503_a(entityPosX, entityPosY, entityPosZ); return field_151504_e != null; } else return false; } }
Example #12
Source File: FlyNodeProcessor.java From EnderZoo with Creative Commons Zero v1.0 Universal | 5 votes |
@Override public int findPathOptions(PathPoint[] pathOptions, PathPoint currentPoint, PathPoint targetPoint, float maxDistance) { EntityLiving entityIn = entity; int i = 0; for (EnumFacing enumfacing : EnumFacing.values()) { PathPoint pathpoint = getSafePoint(entityIn, currentPoint.x + enumfacing.getFrontOffsetX(), currentPoint.y + enumfacing.getFrontOffsetY(), currentPoint.z + enumfacing.getFrontOffsetZ()); if (pathpoint != null && !pathpoint.visited && (pathpoint.distanceTo(targetPoint) < maxDistance)) { pathOptions[i++] = pathpoint; } } return i; }
Example #13
Source File: EntityAIMountedArrowAttack.java From EnderZoo with Creative Commons Zero v1.0 Universal | 5 votes |
private boolean isRunningAway() { if(runningAwayTo == null) { return false; } if(getNavigator().noPath()) { runningAwayTo = null; return false; } PathPoint dest = getNavigator().getPath().getFinalPathPoint(); return dest.equals(runningAwayTo); }
Example #14
Source File: FlyingPathFinder.java From EnderZoo with Creative Commons Zero v1.0 Universal | 4 votes |
private PathPoint[] addToPath(Entity entityIn, PathPoint pathpointStart, PathPoint pathpointEnd, float maxDistance) { // set start point values // pathpointStart.totalPathDistance = 0.0F; // pathpointStart.distanceToNext = pathpointStart.distanceToSquared(pathpointEnd); // pathpointStart.distanceToTarget = pathpointStart.distanceToNext; // pathpointStart.index = -1; PPUtil.setTotalPathDistance(pathpointStart, 0f); float dist = pathpointStart.distanceToSquared(pathpointEnd); PPUtil.setDistanceToNext(pathpointStart, dist); PPUtil.setDistanceToTarget(pathpointStart, dist); PPUtil.setIndex(pathpointStart, -1); // clear and add out start point to the path path.clearPath(); path.addPoint(pathpointStart); PathPoint curPoint = pathpointStart; // while still points in the path while (!path.isPathEmpty()) { PathPoint dequeued = path.dequeue(); // we are at the end if (dequeued.equals(pathpointEnd)) { return createEntityPath(pathpointStart, pathpointEnd); } // if the dequed point is closer to the ned that our current one, make it // the current point if (dequeued.distanceToSquared(pathpointEnd) < curPoint.distanceToSquared(pathpointEnd)) { curPoint = dequeued; } dequeued.visited = true; // find options for the next point in the path int numPathOptions = nodeProcessor.findPathOptions(pathOptions, dequeued, pathpointEnd, maxDistance); //int numPathOptions = nodeProcessor.findPathOptions(pathOptions, entityIn, dequeued, pathpointEnd, maxDistance); for (int j = 0; j < numPathOptions; ++j) { PathPoint cadidatePoint = pathOptions[j]; float newTotalDistance = PPUtil.getTotalPathDistance(dequeued) + dequeued.distanceToSquared(cadidatePoint); if (newTotalDistance < maxDistance * 2.0F && (!cadidatePoint.isAssigned() || newTotalDistance < PPUtil.getTotalPathDistance(cadidatePoint))) { //cadidatePoint.previous = dequeued; PPUtil.setPrevious(cadidatePoint, dequeued); //cadidatePoint.totalPathDistance = newTotalDistance; PPUtil.setTotalPathDistance(cadidatePoint, newTotalDistance); //cadidatePoint.distanceToNext = cadidatePoint.distanceToSquared(pathpointEnd); PPUtil.setDistanceToNext(cadidatePoint, cadidatePoint.distanceToSquared(pathpointEnd)); if (cadidatePoint.isAssigned()) { //path.changeDistance(cadidatePoint, cadidatePoint.totalPathDistance + cadidatePoint.distanceToNext); path.changeDistance(cadidatePoint, PPUtil.getTotalPathDistance(cadidatePoint) + PPUtil.getDistanceToNext(cadidatePoint)); } else { PPUtil.setDistanceToTarget(cadidatePoint, PPUtil.getTotalPathDistance(cadidatePoint) + PPUtil.getDistanceToNext(cadidatePoint)); path.addPoint(cadidatePoint); } } } // PathPoint cadidatePoint = new PathPoint(pathpointEnd.xCoord, pathpointEnd.yCoord, pathpointEnd.zCoord); // float newTotalDistance = dequeued.totalPathDistance + dequeued.distanceToSquared(cadidatePoint); // cadidatePoint.previous = dequeued; // cadidatePoint.totalPathDistance = newTotalDistance; // cadidatePoint.distanceToNext = cadidatePoint.distanceToSquared(pathpointEnd); // if (cadidatePoint.isAssigned()) { // path.changeDistance(cadidatePoint, cadidatePoint.totalPathDistance + cadidatePoint.distanceToNext); // } else { // cadidatePoint.distanceToTarget = cadidatePoint.totalPathDistance + cadidatePoint.distanceToNext; // path.addPoint(cadidatePoint); // } } if (curPoint == pathpointStart) { return null; } else { return createEntityPath(pathpointStart, curPoint); } }
Example #15
Source File: FlyNodeProcessor.java From EnderZoo with Creative Commons Zero v1.0 Universal | 4 votes |
private PathPoint getSafePoint(Entity entityIn, int x, int y, int z) { boolean i = entityFits(entityIn, x, y, z); return i ? openPoint(x, y, z) : null; }
Example #16
Source File: FlyNodeProcessor.java From EnderZoo with Creative Commons Zero v1.0 Universal | 4 votes |
@Override public PathPoint getPathPointToCoords(double x, double y, double z) { EntityLiving entityIn = entity; return openPoint(MathHelper.floor(x - entityIn.width / 2.0F), MathHelper.floor(y), MathHelper.floor(z - entityIn.width / 2.0F)); }
Example #17
Source File: FlyNodeProcessor.java From EnderZoo with Creative Commons Zero v1.0 Universal | 4 votes |
@Override public PathPoint getStart() { EntityLiving entityIn = entity; return openPoint(MathHelper.floor(entityIn.getEntityBoundingBox().minX), MathHelper.floor(entityIn.getEntityBoundingBox().minY + 0.5D), MathHelper.floor(entityIn.getEntityBoundingBox().minZ)); }
Example #18
Source File: EntityAIFlyingAttackOnCollide.java From EnderZoo with Creative Commons Zero v1.0 Universal | 4 votes |
@Override public void updateTask() { EntityLivingBase entitylivingbase = this.attacker.getAttackTarget(); attacker.getLookHelper().setLookPositionWithEntity(entitylivingbase, 30.0F, 30.0F); double distToTargSq = attacker.getDistanceSq(entitylivingbase.posX, entitylivingbase.getEntityBoundingBox().minY, entitylivingbase.posZ); double attackRangSq = getAttackRangeSq(entitylivingbase); --delayCounter; if ((longMemory || attacker.getEntitySenses().canSee(entitylivingbase)) && delayCounter <= 0 && (targetX == 0.0D && targetY == 0.0D && targetZ == 0.0D || entitylivingbase.getDistanceSq(targetX, targetY, targetZ) >= 1.0D || attacker.getRNG().nextFloat() < 0.05F)) { targetX = entitylivingbase.posX; targetY = entitylivingbase.getEntityBoundingBox().minY; targetZ = entitylivingbase.posZ; delayCounter = 4 + attacker.getRNG().nextInt(7); if (canPenalize) { targetX += failedPathFindingPenalty; if (attacker.getNavigator().getPath() != null) { PathPoint finalPathPoint = attacker.getNavigator().getPath().getFinalPathPoint(); if (finalPathPoint != null && entitylivingbase.getDistanceSq(finalPathPoint.x, finalPathPoint.y, finalPathPoint.z) < 1) failedPathFindingPenalty = 0; else failedPathFindingPenalty += 10; } else { failedPathFindingPenalty += 10; } } if (distToTargSq > 1024) { delayCounter += 10; } else if (distToTargSq > 256) { delayCounter += 5; } if (!flyToAttacker(entitylivingbase)) { delayCounter += 15; } } attackTick = Math.max(attackTick - 1, 0); if (distToTargSq <= attackRangSq && attackTick <= 0) { attackTick = 20; if (attacker.getHeldItem(EnumHand.MAIN_HAND) != null) { attacker.swingArm(EnumHand.MAIN_HAND); } attacker.attackEntityAsMob(entitylivingbase); } }
Example #19
Source File: RenderNavigator.java From PneumaticCraft with GNU General Public License v3.0 | 4 votes |
public boolean tracedToDestination(){ if(path == null) return false; PathPoint finalPoint = path.getFinalPathPoint(); return finalPoint.xCoord == targetX && finalPoint.yCoord == targetY && finalPoint.zCoord == targetZ; }
Example #20
Source File: EntityAIMountedAttackOnCollide.java From EnderZoo with Creative Commons Zero v1.0 Universal | 4 votes |
/** * Updates the task */ public void updateTask() { EntityLivingBase target = attacker.getAttackTarget(); attacker.getLookHelper().setLookPositionWithEntity(target, 30.0F, 30.0F); --pathUpdateTimer; double distanceFromAttackerSq = attacker.getDistanceSq(target.posX, target.getEntityBoundingBox().minY, target.posZ); if((longMemory || attacker.getEntitySenses().canSee(target)) && pathUpdateTimer <= 0 && (targetPosX == 0.0D && targetPosY == 0.0D && targetPosZ == 0.0D || target.getDistanceSq(targetPosX, targetPosY, targetPosZ) >= 1.0D || attacker.getRNG().nextFloat() < 0.05F)) { targetPosX = target.posX; targetPosY = target.getEntityBoundingBox().minY; targetPosZ = target.posZ; pathUpdateTimer = failedPathFindingPenalty + 4 + attacker.getRNG().nextInt(7); if(getNavigator().getPath() != null) { PathPoint finalPathPoint = getNavigator().getPath().getFinalPathPoint(); if(finalPathPoint != null && target.getDistanceSq(finalPathPoint.x, finalPathPoint.y, finalPathPoint.z) < 1) { failedPathFindingPenalty = 0; } else { failedPathFindingPenalty += 10; } } else { failedPathFindingPenalty += 10; } if(distanceFromAttackerSq > 1024.0D) { pathUpdateTimer += 10; } else if(distanceFromAttackerSq > 256.0D) { pathUpdateTimer += 5; } if(!getNavigator().tryMoveToEntityLiving(target, getAttackSpeed())) { pathUpdateTimer += 15; } } attackPause = Math.max(attackPause - 1, 0); double d1 = getAttackReach(target); if(distanceFromAttackerSq <= d1 && attackPause <= 20) { attackPause = 20; if(attacker.getHeldItem(EnumHand.MAIN_HAND) != null) { attacker.swingArm(EnumHand.MAIN_HAND); } attacker.attackEntityAsMob(target); } }