u23
This commit is contained in:
parent
2ebb5d6da9
commit
401ebe2324
1261 changed files with 12766 additions and 138431 deletions
166
src/main/java/net/minecraft/pathfinding/Path.java
Executable file
166
src/main/java/net/minecraft/pathfinding/Path.java
Executable file
|
|
@ -0,0 +1,166 @@
|
|||
package net.minecraft.pathfinding;
|
||||
|
||||
import net.minecraft.pathfinding.PathPoint;
|
||||
|
||||
/**+
|
||||
* This portion of EaglercraftX contains deobfuscated Minecraft 1.8 source code.
|
||||
*
|
||||
* Minecraft 1.8.8 bytecode is (c) 2015 Mojang AB. "Do not distribute!"
|
||||
* Mod Coder Pack v9.18 deobfuscation configs are (c) Copyright by the MCP Team
|
||||
*
|
||||
* EaglercraftX 1.8 patch files (c) 2022-2024 lax1dude, ayunami2000. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
public class Path {
|
||||
|
||||
/**+
|
||||
* Contains the points in this path
|
||||
*/
|
||||
private PathPoint[] pathPoints = new PathPoint[1024];
|
||||
private int count;
|
||||
|
||||
/**+
|
||||
* Adds a point to the path
|
||||
*/
|
||||
public PathPoint addPoint(PathPoint point) {
|
||||
if (point.index >= 0) {
|
||||
throw new IllegalStateException("OW KNOWS!");
|
||||
} else {
|
||||
if (this.count == this.pathPoints.length) {
|
||||
PathPoint[] apathpoint = new PathPoint[this.count << 1];
|
||||
System.arraycopy(this.pathPoints, 0, apathpoint, 0, this.count);
|
||||
this.pathPoints = apathpoint;
|
||||
}
|
||||
|
||||
this.pathPoints[this.count] = point;
|
||||
point.index = this.count;
|
||||
this.sortBack(this.count++);
|
||||
return point;
|
||||
}
|
||||
}
|
||||
|
||||
/**+
|
||||
* Clears the path
|
||||
*/
|
||||
public void clearPath() {
|
||||
this.count = 0;
|
||||
}
|
||||
|
||||
/**+
|
||||
* Returns and removes the first point in the path
|
||||
*/
|
||||
public PathPoint dequeue() {
|
||||
PathPoint pathpoint = this.pathPoints[0];
|
||||
this.pathPoints[0] = this.pathPoints[--this.count];
|
||||
this.pathPoints[this.count] = null;
|
||||
if (this.count > 0) {
|
||||
this.sortForward(0);
|
||||
}
|
||||
|
||||
pathpoint.index = -1;
|
||||
return pathpoint;
|
||||
}
|
||||
|
||||
/**+
|
||||
* Changes the provided point's distance to target
|
||||
*/
|
||||
public void changeDistance(PathPoint parPathPoint, float parFloat1) {
|
||||
float f = parPathPoint.distanceToTarget;
|
||||
parPathPoint.distanceToTarget = parFloat1;
|
||||
if (parFloat1 < f) {
|
||||
this.sortBack(parPathPoint.index);
|
||||
} else {
|
||||
this.sortForward(parPathPoint.index);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**+
|
||||
* Sorts a point to the left
|
||||
*/
|
||||
private void sortBack(int parInt1) {
|
||||
PathPoint pathpoint = this.pathPoints[parInt1];
|
||||
|
||||
int i;
|
||||
for (float f = pathpoint.distanceToTarget; parInt1 > 0; parInt1 = i) {
|
||||
i = parInt1 - 1 >> 1;
|
||||
PathPoint pathpoint1 = this.pathPoints[i];
|
||||
if (f >= pathpoint1.distanceToTarget) {
|
||||
break;
|
||||
}
|
||||
|
||||
this.pathPoints[parInt1] = pathpoint1;
|
||||
pathpoint1.index = parInt1;
|
||||
}
|
||||
|
||||
this.pathPoints[parInt1] = pathpoint;
|
||||
pathpoint.index = parInt1;
|
||||
}
|
||||
|
||||
/**+
|
||||
* Sorts a point to the right
|
||||
*/
|
||||
private void sortForward(int parInt1) {
|
||||
PathPoint pathpoint = this.pathPoints[parInt1];
|
||||
float f = pathpoint.distanceToTarget;
|
||||
|
||||
while (true) {
|
||||
int i = 1 + (parInt1 << 1);
|
||||
int j = i + 1;
|
||||
if (i >= this.count) {
|
||||
break;
|
||||
}
|
||||
|
||||
PathPoint pathpoint1 = this.pathPoints[i];
|
||||
float f1 = pathpoint1.distanceToTarget;
|
||||
PathPoint pathpoint2;
|
||||
float f2;
|
||||
if (j >= this.count) {
|
||||
pathpoint2 = null;
|
||||
f2 = Float.POSITIVE_INFINITY;
|
||||
} else {
|
||||
pathpoint2 = this.pathPoints[j];
|
||||
f2 = pathpoint2.distanceToTarget;
|
||||
}
|
||||
|
||||
if (f1 < f2) {
|
||||
if (f1 >= f) {
|
||||
break;
|
||||
}
|
||||
|
||||
this.pathPoints[parInt1] = pathpoint1;
|
||||
pathpoint1.index = parInt1;
|
||||
parInt1 = i;
|
||||
} else {
|
||||
if (f2 >= f) {
|
||||
break;
|
||||
}
|
||||
|
||||
this.pathPoints[parInt1] = pathpoint2;
|
||||
pathpoint2.index = parInt1;
|
||||
parInt1 = j;
|
||||
}
|
||||
}
|
||||
|
||||
this.pathPoints[parInt1] = pathpoint;
|
||||
pathpoint.index = parInt1;
|
||||
}
|
||||
|
||||
/**+
|
||||
* Returns true if this path contains no points
|
||||
*/
|
||||
public boolean isPathEmpty() {
|
||||
return this.count == 0;
|
||||
}
|
||||
}
|
||||
131
src/main/java/net/minecraft/pathfinding/PathEntity.java
Executable file
131
src/main/java/net/minecraft/pathfinding/PathEntity.java
Executable file
|
|
@ -0,0 +1,131 @@
|
|||
package net.minecraft.pathfinding;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.pathfinding.PathPoint;
|
||||
import net.minecraft.util.Vec3;
|
||||
|
||||
/**+
|
||||
* This portion of EaglercraftX contains deobfuscated Minecraft 1.8 source code.
|
||||
*
|
||||
* Minecraft 1.8.8 bytecode is (c) 2015 Mojang AB. "Do not distribute!"
|
||||
* Mod Coder Pack v9.18 deobfuscation configs are (c) Copyright by the MCP Team
|
||||
*
|
||||
* EaglercraftX 1.8 patch files (c) 2022-2024 lax1dude, ayunami2000. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
public class PathEntity {
|
||||
|
||||
private final PathPoint[] points;
|
||||
private int currentPathIndex;
|
||||
private int pathLength;
|
||||
|
||||
public PathEntity(PathPoint[] pathpoints) {
|
||||
this.points = pathpoints;
|
||||
this.pathLength = pathpoints.length;
|
||||
}
|
||||
|
||||
/**+
|
||||
* Directs this path to the next point in its array
|
||||
*/
|
||||
public void incrementPathIndex() {
|
||||
++this.currentPathIndex;
|
||||
}
|
||||
|
||||
/**+
|
||||
* Returns true if this path has reached the end
|
||||
*/
|
||||
public boolean isFinished() {
|
||||
return this.currentPathIndex >= this.pathLength;
|
||||
}
|
||||
|
||||
/**+
|
||||
* returns the last PathPoint of the Array
|
||||
*/
|
||||
public PathPoint getFinalPathPoint() {
|
||||
return this.pathLength > 0 ? this.points[this.pathLength - 1] : null;
|
||||
}
|
||||
|
||||
/**+
|
||||
* return the PathPoint located at the specified PathIndex,
|
||||
* usually the current one
|
||||
*/
|
||||
public PathPoint getPathPointFromIndex(int index) {
|
||||
return this.points[index];
|
||||
}
|
||||
|
||||
public int getCurrentPathLength() {
|
||||
return this.pathLength;
|
||||
}
|
||||
|
||||
public void setCurrentPathLength(int length) {
|
||||
this.pathLength = length;
|
||||
}
|
||||
|
||||
public int getCurrentPathIndex() {
|
||||
return this.currentPathIndex;
|
||||
}
|
||||
|
||||
public void setCurrentPathIndex(int currentPathIndexIn) {
|
||||
this.currentPathIndex = currentPathIndexIn;
|
||||
}
|
||||
|
||||
/**+
|
||||
* Gets the vector of the PathPoint associated with the given
|
||||
* index.
|
||||
*/
|
||||
public Vec3 getVectorFromIndex(Entity entityIn, int index) {
|
||||
double d0 = (double) this.points[index].xCoord + (double) ((int) (entityIn.width + 1.0F)) * 0.5D;
|
||||
double d1 = (double) this.points[index].yCoord;
|
||||
double d2 = (double) this.points[index].zCoord + (double) ((int) (entityIn.width + 1.0F)) * 0.5D;
|
||||
return new Vec3(d0, d1, d2);
|
||||
}
|
||||
|
||||
/**+
|
||||
* returns the current PathEntity target node as Vec3D
|
||||
*/
|
||||
public Vec3 getPosition(Entity entityIn) {
|
||||
return this.getVectorFromIndex(entityIn, this.currentPathIndex);
|
||||
}
|
||||
|
||||
/**+
|
||||
* Returns true if the EntityPath are the same. Non instance
|
||||
* related equals.
|
||||
*/
|
||||
public boolean isSamePath(PathEntity pathentityIn) {
|
||||
if (pathentityIn == null) {
|
||||
return false;
|
||||
} else if (pathentityIn.points.length != this.points.length) {
|
||||
return false;
|
||||
} else {
|
||||
for (int i = 0; i < this.points.length; ++i) {
|
||||
if (this.points[i].xCoord != pathentityIn.points[i].xCoord
|
||||
|| this.points[i].yCoord != pathentityIn.points[i].yCoord
|
||||
|| this.points[i].zCoord != pathentityIn.points[i].zCoord) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**+
|
||||
* Returns true if the final PathPoint in the PathEntity is
|
||||
* equal to Vec3D coords.
|
||||
*/
|
||||
public boolean isDestinationSame(Vec3 vec) {
|
||||
PathPoint pathpoint = this.getFinalPathPoint();
|
||||
return pathpoint == null ? false : pathpoint.xCoord == (int) vec.xCoord && pathpoint.zCoord == (int) vec.zCoord;
|
||||
}
|
||||
}
|
||||
150
src/main/java/net/minecraft/pathfinding/PathFinder.java
Executable file
150
src/main/java/net/minecraft/pathfinding/PathFinder.java
Executable file
|
|
@ -0,0 +1,150 @@
|
|||
package net.minecraft.pathfinding;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.pathfinding.Path;
|
||||
import net.minecraft.pathfinding.PathEntity;
|
||||
import net.minecraft.pathfinding.PathPoint;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.pathfinder.NodeProcessor;
|
||||
|
||||
/**+
|
||||
* This portion of EaglercraftX contains deobfuscated Minecraft 1.8 source code.
|
||||
*
|
||||
* Minecraft 1.8.8 bytecode is (c) 2015 Mojang AB. "Do not distribute!"
|
||||
* Mod Coder Pack v9.18 deobfuscation configs are (c) Copyright by the MCP Team
|
||||
*
|
||||
* EaglercraftX 1.8 patch files (c) 2022-2024 lax1dude, ayunami2000. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
public class PathFinder {
|
||||
|
||||
/**+
|
||||
* The path being generated
|
||||
*/
|
||||
private Path path = new Path();
|
||||
/**+
|
||||
* Selection of path points to add to the path
|
||||
*/
|
||||
private PathPoint[] pathOptions = new PathPoint[32];
|
||||
private NodeProcessor nodeProcessor;
|
||||
|
||||
public PathFinder(NodeProcessor nodeProcessorIn) {
|
||||
this.nodeProcessor = nodeProcessorIn;
|
||||
}
|
||||
|
||||
/**+
|
||||
* Internal implementation of creating a path from an entity to
|
||||
* a point
|
||||
*/
|
||||
public PathEntity createEntityPathTo(IBlockAccess blockaccess, Entity entityFrom, Entity entityTo, float dist) {
|
||||
return this.createEntityPathTo(blockaccess, entityFrom, entityTo.posX, entityTo.getEntityBoundingBox().minY,
|
||||
entityTo.posZ, dist);
|
||||
}
|
||||
|
||||
/**+
|
||||
* Internal implementation of creating a path from an entity to
|
||||
* a point
|
||||
*/
|
||||
public PathEntity createEntityPathTo(IBlockAccess blockaccess, Entity entityIn, BlockPos targetPos, float dist) {
|
||||
return this.createEntityPathTo(blockaccess, entityIn, (double) ((float) targetPos.getX() + 0.5F),
|
||||
(double) ((float) targetPos.getY() + 0.5F), (double) ((float) targetPos.getZ() + 0.5F), dist);
|
||||
}
|
||||
|
||||
/**+
|
||||
* Internal implementation of creating a path from an entity to
|
||||
* a point
|
||||
*/
|
||||
private PathEntity createEntityPathTo(IBlockAccess blockaccess, Entity entityIn, double x, double y, double z,
|
||||
float distance) {
|
||||
this.path.clearPath();
|
||||
this.nodeProcessor.initProcessor(blockaccess, entityIn);
|
||||
PathPoint pathpoint = this.nodeProcessor.getPathPointTo(entityIn);
|
||||
PathPoint pathpoint1 = this.nodeProcessor.getPathPointToCoords(entityIn, x, y, z);
|
||||
PathEntity pathentity = this.addToPath(entityIn, pathpoint, pathpoint1, distance);
|
||||
this.nodeProcessor.postProcess();
|
||||
return pathentity;
|
||||
}
|
||||
|
||||
/**+
|
||||
* Adds a path from start to end and returns the whole path
|
||||
*/
|
||||
private PathEntity addToPath(Entity entityIn, PathPoint pathpointStart, PathPoint pathpointEnd, float maxDistance) {
|
||||
pathpointStart.totalPathDistance = 0.0F;
|
||||
pathpointStart.distanceToNext = pathpointStart.distanceToSquared(pathpointEnd);
|
||||
pathpointStart.distanceToTarget = pathpointStart.distanceToNext;
|
||||
this.path.clearPath();
|
||||
this.path.addPoint(pathpointStart);
|
||||
PathPoint pathpoint = pathpointStart;
|
||||
|
||||
while (!this.path.isPathEmpty()) {
|
||||
PathPoint pathpoint1 = this.path.dequeue();
|
||||
if (pathpoint1.equals(pathpointEnd)) {
|
||||
return this.createEntityPath(pathpointStart, pathpointEnd);
|
||||
}
|
||||
|
||||
if (pathpoint1.distanceToSquared(pathpointEnd) < pathpoint.distanceToSquared(pathpointEnd)) {
|
||||
pathpoint = pathpoint1;
|
||||
}
|
||||
|
||||
pathpoint1.visited = true;
|
||||
int i = this.nodeProcessor.findPathOptions(this.pathOptions, entityIn, pathpoint1, pathpointEnd,
|
||||
maxDistance);
|
||||
|
||||
for (int j = 0; j < i; ++j) {
|
||||
PathPoint pathpoint2 = this.pathOptions[j];
|
||||
float f = pathpoint1.totalPathDistance + pathpoint1.distanceToSquared(pathpoint2);
|
||||
if (f < maxDistance * 2.0F && (!pathpoint2.isAssigned() || f < pathpoint2.totalPathDistance)) {
|
||||
pathpoint2.previous = pathpoint1;
|
||||
pathpoint2.totalPathDistance = f;
|
||||
pathpoint2.distanceToNext = pathpoint2.distanceToSquared(pathpointEnd);
|
||||
if (pathpoint2.isAssigned()) {
|
||||
this.path.changeDistance(pathpoint2, pathpoint2.totalPathDistance + pathpoint2.distanceToNext);
|
||||
} else {
|
||||
pathpoint2.distanceToTarget = pathpoint2.totalPathDistance + pathpoint2.distanceToNext;
|
||||
this.path.addPoint(pathpoint2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pathpoint == pathpointStart) {
|
||||
return null;
|
||||
} else {
|
||||
return this.createEntityPath(pathpointStart, pathpoint);
|
||||
}
|
||||
}
|
||||
|
||||
/**+
|
||||
* Returns a new PathEntity for a given start and end point
|
||||
*/
|
||||
private PathEntity createEntityPath(PathPoint start, PathPoint end) {
|
||||
int i = 1;
|
||||
|
||||
for (PathPoint pathpoint = end; pathpoint.previous != null; pathpoint = pathpoint.previous) {
|
||||
++i;
|
||||
}
|
||||
|
||||
PathPoint[] apathpoint = new PathPoint[i];
|
||||
PathPoint pathpoint1 = end;
|
||||
--i;
|
||||
|
||||
for (apathpoint[i] = end; pathpoint1.previous != null; apathpoint[i] = pathpoint1) {
|
||||
pathpoint1 = pathpoint1.previous;
|
||||
--i;
|
||||
}
|
||||
|
||||
return new PathEntity(apathpoint);
|
||||
}
|
||||
}
|
||||
304
src/main/java/net/minecraft/pathfinding/PathNavigate.java
Executable file
304
src/main/java/net/minecraft/pathfinding/PathNavigate.java
Executable file
|
|
@ -0,0 +1,304 @@
|
|||
package net.minecraft.pathfinding;
|
||||
|
||||
import java.util.List;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.SharedMonsterAttributes;
|
||||
import net.minecraft.entity.ai.attributes.IAttributeInstance;
|
||||
import net.minecraft.pathfinding.PathEntity;
|
||||
import net.minecraft.pathfinding.PathFinder;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.ChunkCache;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**+
|
||||
* This portion of EaglercraftX contains deobfuscated Minecraft 1.8 source code.
|
||||
*
|
||||
* Minecraft 1.8.8 bytecode is (c) 2015 Mojang AB. "Do not distribute!"
|
||||
* Mod Coder Pack v9.18 deobfuscation configs are (c) Copyright by the MCP Team
|
||||
*
|
||||
* EaglercraftX 1.8 patch files (c) 2022-2024 lax1dude, ayunami2000. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
public abstract class PathNavigate {
|
||||
|
||||
protected EntityLiving theEntity;
|
||||
protected World worldObj;
|
||||
protected PathEntity currentPath;
|
||||
protected double speed;
|
||||
private final IAttributeInstance pathSearchRange;
|
||||
private int totalTicks;
|
||||
private int ticksAtLastPos;
|
||||
/**+
|
||||
* Coordinates of the entity's position last time a check was
|
||||
* done (part of monitoring getting 'stuck')
|
||||
*/
|
||||
private Vec3 lastPosCheck = new Vec3(0.0D, 0.0D, 0.0D);
|
||||
private float heightRequirement = 1.0F;
|
||||
private final PathFinder pathFinder;
|
||||
|
||||
public PathNavigate(EntityLiving entitylivingIn, World worldIn) {
|
||||
this.theEntity = entitylivingIn;
|
||||
this.worldObj = worldIn;
|
||||
this.pathSearchRange = entitylivingIn.getEntityAttribute(SharedMonsterAttributes.followRange);
|
||||
this.pathFinder = this.getPathFinder();
|
||||
}
|
||||
|
||||
protected abstract PathFinder getPathFinder();
|
||||
|
||||
/**+
|
||||
* Sets the speed
|
||||
*/
|
||||
public void setSpeed(double speedIn) {
|
||||
this.speed = speedIn;
|
||||
}
|
||||
|
||||
/**+
|
||||
* Gets the maximum distance that the path finding will search
|
||||
* in.
|
||||
*/
|
||||
public float getPathSearchRange() {
|
||||
return (float) this.pathSearchRange.getAttributeValue();
|
||||
}
|
||||
|
||||
/**+
|
||||
* Returns the path to the given coordinates. Args : x, y, z
|
||||
*/
|
||||
public final PathEntity getPathToXYZ(double x, double y, double z) {
|
||||
return this.getPathToPos(new BlockPos(MathHelper.floor_double(x), (int) y, MathHelper.floor_double(z)));
|
||||
}
|
||||
|
||||
/**+
|
||||
* Returns path to given BlockPos
|
||||
*/
|
||||
public PathEntity getPathToPos(BlockPos pos) {
|
||||
if (!this.canNavigate()) {
|
||||
return null;
|
||||
} else {
|
||||
float f = this.getPathSearchRange();
|
||||
this.worldObj.theProfiler.startSection("pathfind");
|
||||
BlockPos blockpos = new BlockPos(this.theEntity);
|
||||
int i = (int) (f + 8.0F);
|
||||
ChunkCache chunkcache = new ChunkCache(this.worldObj, blockpos.add(-i, -i, -i), blockpos.add(i, i, i), 0);
|
||||
PathEntity pathentity = this.pathFinder.createEntityPathTo(chunkcache, this.theEntity, (BlockPos) pos, f);
|
||||
this.worldObj.theProfiler.endSection();
|
||||
return pathentity;
|
||||
}
|
||||
}
|
||||
|
||||
/**+
|
||||
* Try to find and set a path to XYZ. Returns true if
|
||||
* successful. Args : x, y, z, speed
|
||||
*/
|
||||
public boolean tryMoveToXYZ(double x, double y, double z, double speedIn) {
|
||||
PathEntity pathentity = this.getPathToXYZ((double) MathHelper.floor_double(x), (double) ((int) y),
|
||||
(double) MathHelper.floor_double(z));
|
||||
return this.setPath(pathentity, speedIn);
|
||||
}
|
||||
|
||||
/**+
|
||||
* Sets vertical space requirement for path
|
||||
*/
|
||||
public void setHeightRequirement(float jumpHeight) {
|
||||
this.heightRequirement = jumpHeight;
|
||||
}
|
||||
|
||||
/**+
|
||||
* Returns the path to the given EntityLiving. Args : entity
|
||||
*/
|
||||
public PathEntity getPathToEntityLiving(Entity entityIn) {
|
||||
if (!this.canNavigate()) {
|
||||
return null;
|
||||
} else {
|
||||
float f = this.getPathSearchRange();
|
||||
this.worldObj.theProfiler.startSection("pathfind");
|
||||
BlockPos blockpos = (new BlockPos(this.theEntity)).up();
|
||||
int i = (int) (f + 16.0F);
|
||||
ChunkCache chunkcache = new ChunkCache(this.worldObj, blockpos.add(-i, -i, -i), blockpos.add(i, i, i), 0);
|
||||
PathEntity pathentity = this.pathFinder.createEntityPathTo(chunkcache, this.theEntity, (Entity) entityIn,
|
||||
f);
|
||||
this.worldObj.theProfiler.endSection();
|
||||
return pathentity;
|
||||
}
|
||||
}
|
||||
|
||||
/**+
|
||||
* Try to find and set a path to EntityLiving. Returns true if
|
||||
* successful. Args : entity, speed
|
||||
*/
|
||||
public boolean tryMoveToEntityLiving(Entity entityIn, double speedIn) {
|
||||
PathEntity pathentity = this.getPathToEntityLiving(entityIn);
|
||||
return pathentity != null ? this.setPath(pathentity, speedIn) : false;
|
||||
}
|
||||
|
||||
/**+
|
||||
* Sets a new path. If it's diferent from the old path. Checks
|
||||
* to adjust path for sun avoiding, and stores start coords.
|
||||
* Args : path, speed
|
||||
*/
|
||||
public boolean setPath(PathEntity pathentityIn, double speedIn) {
|
||||
if (pathentityIn == null) {
|
||||
this.currentPath = null;
|
||||
return false;
|
||||
} else {
|
||||
if (!pathentityIn.isSamePath(this.currentPath)) {
|
||||
this.currentPath = pathentityIn;
|
||||
}
|
||||
|
||||
this.removeSunnyPath();
|
||||
if (this.currentPath.getCurrentPathLength() == 0) {
|
||||
return false;
|
||||
} else {
|
||||
this.speed = speedIn;
|
||||
Vec3 vec3 = this.getEntityPosition();
|
||||
this.ticksAtLastPos = this.totalTicks;
|
||||
this.lastPosCheck = vec3;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**+
|
||||
* gets the actively used PathEntity
|
||||
*/
|
||||
public PathEntity getPath() {
|
||||
return this.currentPath;
|
||||
}
|
||||
|
||||
public void onUpdateNavigation() {
|
||||
++this.totalTicks;
|
||||
if (!this.noPath()) {
|
||||
if (this.canNavigate()) {
|
||||
this.pathFollow();
|
||||
} else if (this.currentPath != null
|
||||
&& this.currentPath.getCurrentPathIndex() < this.currentPath.getCurrentPathLength()) {
|
||||
Vec3 vec3 = this.getEntityPosition();
|
||||
Vec3 vec31 = this.currentPath.getVectorFromIndex(this.theEntity,
|
||||
this.currentPath.getCurrentPathIndex());
|
||||
if (vec3.yCoord > vec31.yCoord && !this.theEntity.onGround
|
||||
&& MathHelper.floor_double(vec3.xCoord) == MathHelper.floor_double(vec31.xCoord)
|
||||
&& MathHelper.floor_double(vec3.zCoord) == MathHelper.floor_double(vec31.zCoord)) {
|
||||
this.currentPath.setCurrentPathIndex(this.currentPath.getCurrentPathIndex() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.noPath()) {
|
||||
Vec3 vec32 = this.currentPath.getPosition(this.theEntity);
|
||||
if (vec32 != null) {
|
||||
AxisAlignedBB axisalignedbb1 = (new AxisAlignedBB(vec32.xCoord, vec32.yCoord, vec32.zCoord,
|
||||
vec32.xCoord, vec32.yCoord, vec32.zCoord)).expand(0.5D, 0.5D, 0.5D);
|
||||
List list = this.worldObj.getCollidingBoundingBoxes(this.theEntity,
|
||||
axisalignedbb1.addCoord(0.0D, -1.0D, 0.0D));
|
||||
double d0 = -1.0D;
|
||||
axisalignedbb1 = axisalignedbb1.offset(0.0D, 1.0D, 0.0D);
|
||||
|
||||
for (AxisAlignedBB axisalignedbb : (List<AxisAlignedBB>) list) {
|
||||
d0 = axisalignedbb.calculateYOffset(axisalignedbb1, d0);
|
||||
}
|
||||
|
||||
this.theEntity.getMoveHelper().setMoveTo(vec32.xCoord, vec32.yCoord + d0, vec32.zCoord, this.speed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void pathFollow() {
|
||||
Vec3 vec3 = this.getEntityPosition();
|
||||
int i = this.currentPath.getCurrentPathLength();
|
||||
|
||||
for (int j = this.currentPath.getCurrentPathIndex(); j < this.currentPath.getCurrentPathLength(); ++j) {
|
||||
if (this.currentPath.getPathPointFromIndex(j).yCoord != (int) vec3.yCoord) {
|
||||
i = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
float f = this.theEntity.width * this.theEntity.width * this.heightRequirement;
|
||||
|
||||
for (int k = this.currentPath.getCurrentPathIndex(); k < i; ++k) {
|
||||
Vec3 vec31 = this.currentPath.getVectorFromIndex(this.theEntity, k);
|
||||
if (vec3.squareDistanceTo(vec31) < (double) f) {
|
||||
this.currentPath.setCurrentPathIndex(k + 1);
|
||||
}
|
||||
}
|
||||
|
||||
int j1 = MathHelper.ceiling_float_int(this.theEntity.width);
|
||||
int k1 = (int) this.theEntity.height + 1;
|
||||
int l = j1;
|
||||
|
||||
for (int i1 = i - 1; i1 >= this.currentPath.getCurrentPathIndex(); --i1) {
|
||||
if (this.isDirectPathBetweenPoints(vec3, this.currentPath.getVectorFromIndex(this.theEntity, i1), j1, k1,
|
||||
l)) {
|
||||
this.currentPath.setCurrentPathIndex(i1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.checkForStuck(vec3);
|
||||
}
|
||||
|
||||
/**+
|
||||
* Checks if entity haven't been moved when last checked and if
|
||||
* so, clears current {@link
|
||||
* net.minecraft.pathfinding.PathEntity}
|
||||
*/
|
||||
protected void checkForStuck(Vec3 positionVec3) {
|
||||
if (this.totalTicks - this.ticksAtLastPos > 100) {
|
||||
if (positionVec3.squareDistanceTo(this.lastPosCheck) < 2.25D) {
|
||||
this.clearPathEntity();
|
||||
}
|
||||
|
||||
this.ticksAtLastPos = this.totalTicks;
|
||||
this.lastPosCheck = positionVec3;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**+
|
||||
* If null path or reached the end
|
||||
*/
|
||||
public boolean noPath() {
|
||||
return this.currentPath == null || this.currentPath.isFinished();
|
||||
}
|
||||
|
||||
/**+
|
||||
* sets active PathEntity to null
|
||||
*/
|
||||
public void clearPathEntity() {
|
||||
this.currentPath = null;
|
||||
}
|
||||
|
||||
protected abstract Vec3 getEntityPosition();
|
||||
|
||||
protected abstract boolean canNavigate();
|
||||
|
||||
/**+
|
||||
* Returns true if the entity is in water or lava, false
|
||||
* otherwise
|
||||
*/
|
||||
protected boolean isInLiquid() {
|
||||
return this.theEntity.isInWater() || this.theEntity.isInLava();
|
||||
}
|
||||
|
||||
/**+
|
||||
* Trims path data from the end to the first sun covered block
|
||||
*/
|
||||
protected void removeSunnyPath() {
|
||||
}
|
||||
|
||||
protected abstract boolean isDirectPathBetweenPoints(Vec3 var1, Vec3 var2, int var3, int var4, int var5);
|
||||
}
|
||||
90
src/main/java/net/minecraft/pathfinding/PathNavigateClimber.java
Executable file
90
src/main/java/net/minecraft/pathfinding/PathNavigateClimber.java
Executable file
|
|
@ -0,0 +1,90 @@
|
|||
package net.minecraft.pathfinding;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.pathfinding.PathEntity;
|
||||
import net.minecraft.pathfinding.PathNavigateGround;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**+
|
||||
* This portion of EaglercraftX contains deobfuscated Minecraft 1.8 source code.
|
||||
*
|
||||
* Minecraft 1.8.8 bytecode is (c) 2015 Mojang AB. "Do not distribute!"
|
||||
* Mod Coder Pack v9.18 deobfuscation configs are (c) Copyright by the MCP Team
|
||||
*
|
||||
* EaglercraftX 1.8 patch files (c) 2022-2024 lax1dude, ayunami2000. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
public class PathNavigateClimber extends PathNavigateGround {
|
||||
|
||||
private BlockPos targetPosition;
|
||||
|
||||
public PathNavigateClimber(EntityLiving entityLivingIn, World worldIn) {
|
||||
super(entityLivingIn, worldIn);
|
||||
}
|
||||
|
||||
/**+
|
||||
* Returns path to given BlockPos
|
||||
*/
|
||||
public PathEntity getPathToPos(BlockPos blockpos) {
|
||||
this.targetPosition = blockpos;
|
||||
return super.getPathToPos(blockpos);
|
||||
}
|
||||
|
||||
/**+
|
||||
* Returns the path to the given EntityLiving. Args : entity
|
||||
*/
|
||||
public PathEntity getPathToEntityLiving(Entity entity) {
|
||||
this.targetPosition = new BlockPos(entity);
|
||||
return super.getPathToEntityLiving(entity);
|
||||
}
|
||||
|
||||
/**+
|
||||
* Try to find and set a path to EntityLiving. Returns true if
|
||||
* successful. Args : entity, speed
|
||||
*/
|
||||
public boolean tryMoveToEntityLiving(Entity entity, double d0) {
|
||||
PathEntity pathentity = this.getPathToEntityLiving(entity);
|
||||
if (pathentity != null) {
|
||||
return this.setPath(pathentity, d0);
|
||||
} else {
|
||||
this.targetPosition = new BlockPos(entity);
|
||||
this.speed = d0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void onUpdateNavigation() {
|
||||
if (!this.noPath()) {
|
||||
super.onUpdateNavigation();
|
||||
} else {
|
||||
if (this.targetPosition != null) {
|
||||
double d0 = (double) (this.theEntity.width * this.theEntity.width);
|
||||
if (this.theEntity.getDistanceSqToCenter(this.targetPosition) >= d0
|
||||
&& (this.theEntity.posY <= (double) this.targetPosition.getY()
|
||||
|| this.theEntity.getDistanceSqToCenter(new BlockPos(this.targetPosition.getX(),
|
||||
MathHelper.floor_double(this.theEntity.posY),
|
||||
this.targetPosition.getZ())) >= d0)) {
|
||||
this.theEntity.getMoveHelper().setMoveTo((double) this.targetPosition.getX(),
|
||||
(double) this.targetPosition.getY(), (double) this.targetPosition.getZ(), this.speed);
|
||||
} else {
|
||||
this.targetPosition = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
270
src/main/java/net/minecraft/pathfinding/PathNavigateGround.java
Executable file
270
src/main/java/net/minecraft/pathfinding/PathNavigateGround.java
Executable file
|
|
@ -0,0 +1,270 @@
|
|||
package net.minecraft.pathfinding;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.monster.EntityZombie;
|
||||
import net.minecraft.entity.passive.EntityChicken;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.pathfinding.PathFinder;
|
||||
import net.minecraft.pathfinding.PathNavigate;
|
||||
import net.minecraft.pathfinding.PathPoint;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.pathfinder.WalkNodeProcessor;
|
||||
|
||||
/**+
|
||||
* This portion of EaglercraftX contains deobfuscated Minecraft 1.8 source code.
|
||||
*
|
||||
* Minecraft 1.8.8 bytecode is (c) 2015 Mojang AB. "Do not distribute!"
|
||||
* Mod Coder Pack v9.18 deobfuscation configs are (c) Copyright by the MCP Team
|
||||
*
|
||||
* EaglercraftX 1.8 patch files (c) 2022-2024 lax1dude, ayunami2000. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
public class PathNavigateGround extends PathNavigate {
|
||||
|
||||
protected WalkNodeProcessor nodeProcessor;
|
||||
private boolean shouldAvoidSun;
|
||||
|
||||
public PathNavigateGround(EntityLiving entitylivingIn, World worldIn) {
|
||||
super(entitylivingIn, worldIn);
|
||||
}
|
||||
|
||||
protected PathFinder getPathFinder() {
|
||||
this.nodeProcessor = new WalkNodeProcessor();
|
||||
this.nodeProcessor.setEnterDoors(true);
|
||||
return new PathFinder(this.nodeProcessor);
|
||||
}
|
||||
|
||||
/**+
|
||||
* If on ground or swimming and can swim
|
||||
*/
|
||||
protected boolean canNavigate() {
|
||||
return this.theEntity.onGround || this.getCanSwim() && this.isInLiquid() || this.theEntity.isRiding()
|
||||
&& this.theEntity instanceof EntityZombie && this.theEntity.ridingEntity instanceof EntityChicken;
|
||||
}
|
||||
|
||||
protected Vec3 getEntityPosition() {
|
||||
return new Vec3(this.theEntity.posX, (double) this.getPathablePosY(), this.theEntity.posZ);
|
||||
}
|
||||
|
||||
/**+
|
||||
* Gets the safe pathing Y position for the entity depending on
|
||||
* if it can path swim or not
|
||||
*/
|
||||
private int getPathablePosY() {
|
||||
if (this.theEntity.isInWater() && this.getCanSwim()) {
|
||||
int i = (int) this.theEntity.getEntityBoundingBox().minY;
|
||||
Block block = this.worldObj.getBlockState(new BlockPos(MathHelper.floor_double(this.theEntity.posX), i,
|
||||
MathHelper.floor_double(this.theEntity.posZ))).getBlock();
|
||||
int j = 0;
|
||||
|
||||
while (block == Blocks.flowing_water || block == Blocks.water) {
|
||||
++i;
|
||||
block = this.worldObj.getBlockState(new BlockPos(MathHelper.floor_double(this.theEntity.posX), i,
|
||||
MathHelper.floor_double(this.theEntity.posZ))).getBlock();
|
||||
++j;
|
||||
if (j > 16) {
|
||||
return (int) this.theEntity.getEntityBoundingBox().minY;
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
} else {
|
||||
return (int) (this.theEntity.getEntityBoundingBox().minY + 0.5D);
|
||||
}
|
||||
}
|
||||
|
||||
/**+
|
||||
* Trims path data from the end to the first sun covered block
|
||||
*/
|
||||
protected void removeSunnyPath() {
|
||||
super.removeSunnyPath();
|
||||
if (this.shouldAvoidSun) {
|
||||
if (this.worldObj.canSeeSky(new BlockPos(MathHelper.floor_double(this.theEntity.posX),
|
||||
(int) (this.theEntity.getEntityBoundingBox().minY + 0.5D),
|
||||
MathHelper.floor_double(this.theEntity.posZ)))) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.currentPath.getCurrentPathLength(); ++i) {
|
||||
PathPoint pathpoint = this.currentPath.getPathPointFromIndex(i);
|
||||
if (this.worldObj.canSeeSky(new BlockPos(pathpoint.xCoord, pathpoint.yCoord, pathpoint.zCoord))) {
|
||||
this.currentPath.setCurrentPathLength(i - 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**+
|
||||
* Returns true when an entity of specified size could safely
|
||||
* walk in a straight line between the two points. Args: pos1,
|
||||
* pos2, entityXSize, entityYSize, entityZSize
|
||||
*/
|
||||
protected boolean isDirectPathBetweenPoints(Vec3 posVec31, Vec3 posVec32, int sizeX, int sizeY, int sizeZ) {
|
||||
int i = MathHelper.floor_double(posVec31.xCoord);
|
||||
int j = MathHelper.floor_double(posVec31.zCoord);
|
||||
double d0 = posVec32.xCoord - posVec31.xCoord;
|
||||
double d1 = posVec32.zCoord - posVec31.zCoord;
|
||||
double d2 = d0 * d0 + d1 * d1;
|
||||
if (d2 < 1.0E-8D) {
|
||||
return false;
|
||||
} else {
|
||||
double d3 = 1.0D / Math.sqrt(d2);
|
||||
d0 = d0 * d3;
|
||||
d1 = d1 * d3;
|
||||
sizeX = sizeX + 2;
|
||||
sizeZ = sizeZ + 2;
|
||||
if (!this.isSafeToStandAt(i, (int) posVec31.yCoord, j, sizeX, sizeY, sizeZ, posVec31, d0, d1)) {
|
||||
return false;
|
||||
} else {
|
||||
sizeX = sizeX - 2;
|
||||
sizeZ = sizeZ - 2;
|
||||
double d4 = 1.0D / Math.abs(d0);
|
||||
double d5 = 1.0D / Math.abs(d1);
|
||||
double d6 = (double) (i * 1) - posVec31.xCoord;
|
||||
double d7 = (double) (j * 1) - posVec31.zCoord;
|
||||
if (d0 >= 0.0D) {
|
||||
++d6;
|
||||
}
|
||||
|
||||
if (d1 >= 0.0D) {
|
||||
++d7;
|
||||
}
|
||||
|
||||
d6 = d6 / d0;
|
||||
d7 = d7 / d1;
|
||||
int k = d0 < 0.0D ? -1 : 1;
|
||||
int l = d1 < 0.0D ? -1 : 1;
|
||||
int i1 = MathHelper.floor_double(posVec32.xCoord);
|
||||
int j1 = MathHelper.floor_double(posVec32.zCoord);
|
||||
int k1 = i1 - i;
|
||||
int l1 = j1 - j;
|
||||
|
||||
while (k1 * k > 0 || l1 * l > 0) {
|
||||
if (d6 < d7) {
|
||||
d6 += d4;
|
||||
i += k;
|
||||
k1 = i1 - i;
|
||||
} else {
|
||||
d7 += d5;
|
||||
j += l;
|
||||
l1 = j1 - j;
|
||||
}
|
||||
|
||||
if (!this.isSafeToStandAt(i, (int) posVec31.yCoord, j, sizeX, sizeY, sizeZ, posVec31, d0, d1)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**+
|
||||
* Returns true when an entity could stand at a position,
|
||||
* including solid blocks under the entire entity.
|
||||
*/
|
||||
private boolean isSafeToStandAt(int x, int y, int z, int sizeX, int sizeY, int sizeZ, Vec3 vec31, double parDouble1,
|
||||
double parDouble2) {
|
||||
int i = x - sizeX / 2;
|
||||
int j = z - sizeZ / 2;
|
||||
if (!this.isPositionClear(i, y, j, sizeX, sizeY, sizeZ, vec31, parDouble1, parDouble2)) {
|
||||
return false;
|
||||
} else {
|
||||
for (int k = i; k < i + sizeX; ++k) {
|
||||
for (int l = j; l < j + sizeZ; ++l) {
|
||||
double d0 = (double) k + 0.5D - vec31.xCoord;
|
||||
double d1 = (double) l + 0.5D - vec31.zCoord;
|
||||
if (d0 * parDouble1 + d1 * parDouble2 >= 0.0D) {
|
||||
Block block = this.worldObj.getBlockState(new BlockPos(k, y - 1, l)).getBlock();
|
||||
Material material = block.getMaterial();
|
||||
if (material == Material.air) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (material == Material.water && !this.theEntity.isInWater()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (material == Material.lava) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**+
|
||||
* Returns true if an entity does not collide with any solid
|
||||
* blocks at the position.
|
||||
*/
|
||||
private boolean isPositionClear(int parInt1, int parInt2, int parInt3, int parInt4, int parInt5, int parInt6,
|
||||
Vec3 parVec3_1, double parDouble1, double parDouble2) {
|
||||
for (BlockPos blockpos : BlockPos.getAllInBox(new BlockPos(parInt1, parInt2, parInt3),
|
||||
new BlockPos(parInt1 + parInt4 - 1, parInt2 + parInt5 - 1, parInt3 + parInt6 - 1))) {
|
||||
double d0 = (double) blockpos.getX() + 0.5D - parVec3_1.xCoord;
|
||||
double d1 = (double) blockpos.getZ() + 0.5D - parVec3_1.zCoord;
|
||||
if (d0 * parDouble1 + d1 * parDouble2 >= 0.0D) {
|
||||
Block block = this.worldObj.getBlockState(blockpos).getBlock();
|
||||
if (!block.isPassable(this.worldObj, blockpos)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setAvoidsWater(boolean avoidsWater) {
|
||||
this.nodeProcessor.setAvoidsWater(avoidsWater);
|
||||
}
|
||||
|
||||
public boolean getAvoidsWater() {
|
||||
return this.nodeProcessor.getAvoidsWater();
|
||||
}
|
||||
|
||||
public void setBreakDoors(boolean canBreakDoors) {
|
||||
this.nodeProcessor.setBreakDoors(canBreakDoors);
|
||||
}
|
||||
|
||||
public void setEnterDoors(boolean par1) {
|
||||
this.nodeProcessor.setEnterDoors(par1);
|
||||
}
|
||||
|
||||
public boolean getEnterDoors() {
|
||||
return this.nodeProcessor.getEnterDoors();
|
||||
}
|
||||
|
||||
public void setCanSwim(boolean canSwim) {
|
||||
this.nodeProcessor.setCanSwim(canSwim);
|
||||
}
|
||||
|
||||
public boolean getCanSwim() {
|
||||
return this.nodeProcessor.getCanSwim();
|
||||
}
|
||||
|
||||
public void setAvoidSun(boolean par1) {
|
||||
this.shouldAvoidSun = par1;
|
||||
}
|
||||
}
|
||||
93
src/main/java/net/minecraft/pathfinding/PathNavigateSwimmer.java
Executable file
93
src/main/java/net/minecraft/pathfinding/PathNavigateSwimmer.java
Executable file
|
|
@ -0,0 +1,93 @@
|
|||
package net.minecraft.pathfinding;
|
||||
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.pathfinding.PathFinder;
|
||||
import net.minecraft.pathfinding.PathNavigate;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.pathfinder.SwimNodeProcessor;
|
||||
|
||||
/**+
|
||||
* This portion of EaglercraftX contains deobfuscated Minecraft 1.8 source code.
|
||||
*
|
||||
* Minecraft 1.8.8 bytecode is (c) 2015 Mojang AB. "Do not distribute!"
|
||||
* Mod Coder Pack v9.18 deobfuscation configs are (c) Copyright by the MCP Team
|
||||
*
|
||||
* EaglercraftX 1.8 patch files (c) 2022-2024 lax1dude, ayunami2000. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
public class PathNavigateSwimmer extends PathNavigate {
|
||||
|
||||
public PathNavigateSwimmer(EntityLiving entitylivingIn, World worldIn) {
|
||||
super(entitylivingIn, worldIn);
|
||||
}
|
||||
|
||||
protected PathFinder getPathFinder() {
|
||||
return new PathFinder(new SwimNodeProcessor());
|
||||
}
|
||||
|
||||
/**+
|
||||
* If on ground or swimming and can swim
|
||||
*/
|
||||
protected boolean canNavigate() {
|
||||
return this.isInLiquid();
|
||||
}
|
||||
|
||||
protected Vec3 getEntityPosition() {
|
||||
return new Vec3(this.theEntity.posX, this.theEntity.posY + (double) this.theEntity.height * 0.5D,
|
||||
this.theEntity.posZ);
|
||||
}
|
||||
|
||||
protected void pathFollow() {
|
||||
Vec3 vec3 = this.getEntityPosition();
|
||||
float f = this.theEntity.width * this.theEntity.width;
|
||||
byte b0 = 6;
|
||||
if (vec3.squareDistanceTo(this.currentPath.getVectorFromIndex(this.theEntity,
|
||||
this.currentPath.getCurrentPathIndex())) < (double) f) {
|
||||
this.currentPath.incrementPathIndex();
|
||||
}
|
||||
|
||||
for (int i = Math.min(this.currentPath.getCurrentPathIndex() + b0,
|
||||
this.currentPath.getCurrentPathLength() - 1); i > this.currentPath.getCurrentPathIndex(); --i) {
|
||||
Vec3 vec31 = this.currentPath.getVectorFromIndex(this.theEntity, i);
|
||||
if (vec31.squareDistanceTo(vec3) <= 36.0D && this.isDirectPathBetweenPoints(vec3, vec31, 0, 0, 0)) {
|
||||
this.currentPath.setCurrentPathIndex(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.checkForStuck(vec3);
|
||||
}
|
||||
|
||||
/**+
|
||||
* Trims path data from the end to the first sun covered block
|
||||
*/
|
||||
protected void removeSunnyPath() {
|
||||
super.removeSunnyPath();
|
||||
}
|
||||
|
||||
/**+
|
||||
* Returns true when an entity of specified size could safely
|
||||
* walk in a straight line between the two points. Args: pos1,
|
||||
* pos2, entityXSize, entityYSize, entityZSize
|
||||
*/
|
||||
protected boolean isDirectPathBetweenPoints(Vec3 vec3, Vec3 vec31, int var3, int var4, int var5) {
|
||||
MovingObjectPosition movingobjectposition = this.worldObj.rayTraceBlocks(vec3,
|
||||
new Vec3(vec31.xCoord, vec31.yCoord + (double) this.theEntity.height * 0.5D, vec31.zCoord), false, true,
|
||||
false);
|
||||
return movingobjectposition == null
|
||||
|| movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.MISS;
|
||||
}
|
||||
}
|
||||
95
src/main/java/net/minecraft/pathfinding/PathPoint.java
Executable file
95
src/main/java/net/minecraft/pathfinding/PathPoint.java
Executable file
|
|
@ -0,0 +1,95 @@
|
|||
package net.minecraft.pathfinding;
|
||||
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
||||
/**+
|
||||
* This portion of EaglercraftX contains deobfuscated Minecraft 1.8 source code.
|
||||
*
|
||||
* Minecraft 1.8.8 bytecode is (c) 2015 Mojang AB. "Do not distribute!"
|
||||
* Mod Coder Pack v9.18 deobfuscation configs are (c) Copyright by the MCP Team
|
||||
*
|
||||
* EaglercraftX 1.8 patch files (c) 2022-2024 lax1dude, ayunami2000. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
public class PathPoint {
|
||||
|
||||
public final int xCoord;
|
||||
public final int yCoord;
|
||||
public final int zCoord;
|
||||
private final int hash;
|
||||
int index = -1;
|
||||
float totalPathDistance;
|
||||
float distanceToNext;
|
||||
float distanceToTarget;
|
||||
PathPoint previous;
|
||||
public boolean visited;
|
||||
|
||||
public PathPoint(int x, int y, int z) {
|
||||
this.xCoord = x;
|
||||
this.yCoord = y;
|
||||
this.zCoord = z;
|
||||
this.hash = makeHash(x, y, z);
|
||||
}
|
||||
|
||||
public static int makeHash(int x, int y, int z) {
|
||||
return y & 255 | (x & 32767) << 8 | (z & 32767) << 24 | (x < 0 ? Integer.MIN_VALUE : 0)
|
||||
| (z < 0 ? '\u8000' : 0);
|
||||
}
|
||||
|
||||
/**+
|
||||
* Returns the linear distance to another path point
|
||||
*/
|
||||
public float distanceTo(PathPoint pathpointIn) {
|
||||
float f = (float) (pathpointIn.xCoord - this.xCoord);
|
||||
float f1 = (float) (pathpointIn.yCoord - this.yCoord);
|
||||
float f2 = (float) (pathpointIn.zCoord - this.zCoord);
|
||||
return MathHelper.sqrt_float(f * f + f1 * f1 + f2 * f2);
|
||||
}
|
||||
|
||||
/**+
|
||||
* Returns the squared distance to another path point
|
||||
*/
|
||||
public float distanceToSquared(PathPoint pathpointIn) {
|
||||
float f = (float) (pathpointIn.xCoord - this.xCoord);
|
||||
float f1 = (float) (pathpointIn.yCoord - this.yCoord);
|
||||
float f2 = (float) (pathpointIn.zCoord - this.zCoord);
|
||||
return f * f + f1 * f1 + f2 * f2;
|
||||
}
|
||||
|
||||
public boolean equals(Object object) {
|
||||
if (!(object instanceof PathPoint)) {
|
||||
return false;
|
||||
} else {
|
||||
PathPoint pathpoint = (PathPoint) object;
|
||||
return this.hash == pathpoint.hash && this.xCoord == pathpoint.xCoord && this.yCoord == pathpoint.yCoord
|
||||
&& this.zCoord == pathpoint.zCoord;
|
||||
}
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.hash;
|
||||
}
|
||||
|
||||
/**+
|
||||
* Returns true if this point has already been assigned to a
|
||||
* path
|
||||
*/
|
||||
public boolean isAssigned() {
|
||||
return this.index >= 0;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.xCoord + ", " + this.yCoord + ", " + this.zCoord;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue