Skip to content

Commit

Permalink
Add door opener for Citizens pathfinder
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Mar 8, 2014
1 parent 04c1ff2 commit 2068c55
Showing 1 changed file with 21 additions and 1 deletion.
Expand Up @@ -31,6 +31,10 @@ public float getCost(BlockSource source, PathPoint point) {
return 0.5F; // TODO: add light level-specific costs
}

private boolean isDoor(Material in) {
return DOORS.contains(in);
}

@Override
public PassableState isPassable(BlockSource source, PathPoint point) {
Vector pos = point.getVector();
Expand All @@ -42,6 +46,8 @@ public PassableState isPassable(BlockSource source, PathPoint point) {
}
if ((above == Material.LADDER && in == Material.LADDER) || (in == Material.LADDER && below == Material.LADDER)) {
point.addCallback(new LadderClimber());
} else if (isDoor(in)) {
point.addCallback(new DoorOpener());
} else if (!canStandIn(above) || !canStandIn(in)) {
return PassableState.UNPASSABLE;
}
Expand All @@ -58,7 +64,19 @@ public PassableState isPassable(BlockSource source, PathPoint point) {
return PassableState.PASSABLE;
}

private final class LadderClimber implements PathCallback {
private class DoorOpener implements PathCallback {
@Override
@SuppressWarnings("deprecation")
public void run(NPC npc, Block point, double radius) {
if (radius < 2) {
boolean bottom = (point.getData() & 8) == 0;
Block set = bottom ? point : point.getRelative(BlockFace.DOWN);
set.setData((byte) ((set.getData() & 7) | 4));
}
}
}

private class LadderClimber implements PathCallback {
boolean added = false;

@Override
Expand Down Expand Up @@ -143,6 +161,8 @@ public static boolean validPosition(Block in) {
&& canStandOn(in.getRelative(BlockFace.DOWN));
}

private static final Set<Material> DOORS = EnumSet.of(Material.IRON_DOOR, Material.IRON_DOOR_BLOCK,
Material.WOODEN_DOOR, Material.WOOD_DOOR);
private static final Vector DOWN = new Vector(0, -1, 0);
private static final Set<Material> NOT_JUMPABLE = EnumSet.of(Material.FENCE, Material.IRON_FENCE,
Material.NETHER_FENCE, Material.COBBLE_WALL);
Expand Down

0 comments on commit 2068c55

Please sign in to comment.