-
-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improves builder pathfinding, they no longer try to reach air corners of the schematic Builders now got a dedicated pathjob for finding a suitable position to build on, which is the smallest distance from build position and building location
- Loading branch information
Showing
6 changed files
with
156 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveCloseToXNearY.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.minecolonies.core.entity.pathfinding.pathjobs; | ||
|
||
import com.minecolonies.api.util.BlockPosUtil; | ||
import com.minecolonies.api.util.ShapeUtil; | ||
import com.minecolonies.core.entity.pathfinding.MNode; | ||
import com.minecolonies.core.entity.pathfinding.PathfindingUtils; | ||
import com.minecolonies.core.entity.pathfinding.SurfaceType; | ||
import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.entity.Mob; | ||
import net.minecraft.world.level.Level; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Job that handles moving close to a position near another | ||
*/ | ||
public class PathJobMoveCloseToXNearY extends AbstractPathJob | ||
{ | ||
/** | ||
* Position to go close to | ||
*/ | ||
protected final BlockPos desiredPosition; | ||
|
||
/** | ||
* Position to stay nearby | ||
*/ | ||
protected final BlockPos nearbyPosition; | ||
|
||
/** | ||
* Required distance to reach | ||
*/ | ||
protected final int distToDesired; | ||
|
||
public PathJobMoveCloseToXNearY( | ||
final Level world, | ||
final BlockPos desiredPosition, | ||
final BlockPos nearbyPosition, | ||
final int distToDesired, | ||
final Mob entity) | ||
{ | ||
super(world, PathfindingUtils.prepareStart(entity), desiredPosition, new PathResult<PathJobMoveCloseToXNearY>(), entity); | ||
|
||
this.desiredPosition = desiredPosition; | ||
this.nearbyPosition = nearbyPosition; | ||
this.distToDesired = distToDesired; | ||
extraNodes = 20; | ||
maxNodes /= 2; | ||
} | ||
|
||
@Override | ||
protected double computeHeuristic(final int x, final int y, final int z) | ||
{ | ||
return BlockPosUtil.distManhattan(desiredPosition, x, y, z) * 2 + BlockPosUtil.distManhattan(nearbyPosition, x, y, z); | ||
} | ||
|
||
@Override | ||
protected boolean isAtDestination(@NotNull final MNode n) | ||
{ | ||
return BlockPosUtil.distManhattan(desiredPosition, n.x, n.y, n.z) < distToDesired | ||
&& SurfaceType.getSurfaceType(world, cachedBlockLookup.getBlockState(n.x, n.y - 1, n.z), tempWorldPos.set(n.x, n.y - 1, n.z), getPathingOptions()) | ||
== SurfaceType.WALKABLE; | ||
} | ||
|
||
@Override | ||
protected double getEndNodeScore(@NotNull final MNode n) | ||
{ | ||
return BlockPosUtil.distManhattan(desiredPosition, n.x, n.y, n.z) * 2 + BlockPosUtil.distManhattan(nearbyPosition, n.x, n.y, n.z); | ||
} | ||
|
||
@Override | ||
protected boolean stopOnNodeLimit(final int totalNodesVisited, final MNode bestNode, final int nodesSinceEndNode) | ||
{ | ||
if (nodesSinceEndNode > 200) | ||
{ | ||
return true; | ||
} | ||
else | ||
{ | ||
maxNodes += 200; | ||
return false; | ||
} | ||
} | ||
} |