Skip to content

Commit

Permalink
Prevent builder from standing where hes mining below (#9981)
Browse files Browse the repository at this point in the history
Prevent builder from standing where hes mining below
Prevent builder from dropping down when searching for a building position
Add strong preference for standing outside of water while building
  • Loading branch information
someaddons authored Jun 10, 2024
1 parent 758292b commit b5be09c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,23 @@ public IAIState afterDump()
@Override
public boolean walkToConstructionSite(final BlockPos currentBlock)
{
if (workFrom != null && workFrom.getX() == currentBlock.getX() && workFrom.getZ() == currentBlock.getZ() && workFrom.getY() >= currentBlock.getY())
{
// Reset working position when standing ontop
workFrom = null;
}

if (workFrom == null)
{
if (gotoPath == null || gotoPath.isCancelled())
{
gotoPath = ((MinecoloniesAdvancedPathNavigate) worker.getNavigation()).setPathJob(new PathJobMoveCloseToXNearY(world,
final PathJobMoveCloseToXNearY pathJob = new PathJobMoveCloseToXNearY(world,
currentBlock,
job.getWorkOrder().getLocation(),
5,
worker), currentBlock, 1.0, false);
worker);
gotoPath = ((MinecoloniesAdvancedPathNavigate) worker.getNavigation()).setPathJob(pathJob, currentBlock, 1.0, false);
pathJob.getPathingOptions().canDrop = false;
}
else if (gotoPath.isDone())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public void checkStuck(final AbstractAdvancedPathNavigate navigator)
{
if (navigator.getDesiredPos() == null || navigator.getDesiredPos().equals(BlockPos.ZERO))
{
resetGlobalStuckTimers();
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1455,16 +1455,6 @@ else if (!below.isAir())
return -100;
}

/**
* Whether we can drop down multiple blocks
*
* @return
*/
protected boolean canDrop()
{
return true;
}

/**
* Handles goto position in liquid
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import org.jetbrains.annotations.NotNull;

/**
Expand Down Expand Up @@ -56,6 +57,11 @@ protected double computeHeuristic(final int x, final int y, final int z)
@Override
protected boolean isAtDestination(@NotNull final MNode n)
{
if (desiredPosition.getX() == n.x && desiredPosition.getZ() == n.z)
{
return false;
}

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;
Expand All @@ -64,7 +70,22 @@ protected boolean isAtDestination(@NotNull final MNode n)
@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);
if (desiredPosition.getX() == n.x && desiredPosition.getZ() == n.z)
{
return 1000;
}

double dist = BlockPosUtil.distManhattan(desiredPosition, n.x, n.y, n.z) * 2 + BlockPosUtil.distManhattan(nearbyPosition, n.x, n.y, n.z);
if (n.isSwimming())
{
dist += 50;
}
else if (cachedBlockLookup.getBlockState(n.x, n.y - 1, n.z) == Blocks.WATER.defaultBlockState())
{
dist += 50;
}

return dist;
}

@Override
Expand Down

0 comments on commit b5be09c

Please # to comment.