Skip to content

Commit

Permalink
Add new method for pathfinding checks
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jun 28, 2021
1 parent 73de052 commit dab2387
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Expand Up @@ -200,6 +200,19 @@ public static Location findValidLocation(Location location, int radius, int yrad
return location;
}

public static Location findValidLocationAbove(Location location, int radius) {
Block base = location.getBlock();
if (canStandOn(base.getRelative(BlockFace.DOWN)))
return location;
for (int y = 0; y <= radius; y++) {
Block relative = base.getRelative(0, y, 0);
if (canStandOn(relative.getRelative(BlockFace.DOWN))) {
return relative.getLocation();
}
}
return location;
}

public static boolean isDoor(Material in) {
return in.name().contains("DOOR") && !in.name().contains("TRAPDOOR");
}
Expand Down Expand Up @@ -238,7 +251,6 @@ public static boolean validPosition(Block in) {
private static final Set<Material> NOT_JUMPABLE = EnumSet.of(Material.SPRUCE_FENCE, Material.BIRCH_FENCE,
Material.JUNGLE_FENCE, Material.ACACIA_FENCE, Material.DARK_OAK_FENCE);
private static final Set<Material> UNWALKABLE = EnumSet.of(Material.AIR, Material.CACTUS);

private static Material WEB = SpigotUtil.isUsing1_13API() ? Material.COBWEB : Material.valueOf("WEB");

static {
Expand Down
Expand Up @@ -11,7 +11,7 @@ public class VectorGoal implements AStarGoal<VectorNode> {

public VectorGoal(Location dest, float range) {
if (!MinecraftBlockExaminer.canStandIn(dest.getBlock().getType())) {
dest = MinecraftBlockExaminer.findValidLocation(dest, 1);
dest = MinecraftBlockExaminer.findValidLocationAbove(dest, 2);
}
this.leeway = range;
this.goal = dest.toVector();
Expand Down

0 comments on commit dab2387

Please sign in to comment.