diff --git a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/MinecraftGraph.java b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/MinecraftGraph.java index cadd0937c..1667b55b0 100644 --- a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/MinecraftGraph.java +++ b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/MinecraftGraph.java @@ -121,7 +121,7 @@ private GraphAction[] generateTemplateActions(ActionDirection fromDirection) { var actions = new GraphAction[ACTIONS_TEMPLATE.length]; for (var i = 0; i < ACTIONS_TEMPLATE.length; i++) { var action = ACTIONS_TEMPLATE[i]; - if (fromDirection != null && action.actionDirection.opposite() == fromDirection) { + if (fromDirection != null && action.actionDirection.isOpposite(fromDirection)) { continue; } diff --git a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/ActionDirection.java b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/ActionDirection.java index 1b152e39b..3fa089f60 100644 --- a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/ActionDirection.java +++ b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/ActionDirection.java @@ -23,35 +23,85 @@ @Getter @RequiredArgsConstructor public enum ActionDirection { - NORTH, - SOUTH, - EAST, - WEST, - NORTH_EAST, - NORTH_WEST, - SOUTH_EAST, - SOUTH_WEST, - UP, - DOWN, + NORTH { + @Override + public boolean isOpposite(ActionDirection direction) { + return direction == SOUTH; + } + }, + SOUTH { + @Override + public boolean isOpposite(ActionDirection direction) { + return direction == NORTH; + } + }, + EAST { + @Override + public boolean isOpposite(ActionDirection direction) { + return direction == WEST; + } + }, + WEST { + @Override + public boolean isOpposite(ActionDirection direction) { + return direction == EAST; + } + }, + NORTH_EAST { + @Override + public boolean isOpposite(ActionDirection direction) { + return direction == SOUTH_WEST || direction == SOUTH || direction == WEST; + } + }, + NORTH_WEST { + @Override + public boolean isOpposite(ActionDirection direction) { + return direction == SOUTH_EAST || direction == SOUTH || direction == EAST; + } + }, + SOUTH_EAST { + @Override + public boolean isOpposite(ActionDirection direction) { + return direction == NORTH_WEST || direction == NORTH || direction == WEST; + } + }, + SOUTH_WEST { + @Override + public boolean isOpposite(ActionDirection direction) { + return direction == NORTH_EAST || direction == NORTH || direction == EAST; + } + }, + UP { + @Override + public boolean isOpposite(ActionDirection direction) { + return direction == DOWN; + } + }, + DOWN { + @Override + public boolean isOpposite(ActionDirection direction) { + return direction == UP; + } + }, // Jumps, diagonal jumps, falls, diagonal falls, etc. // For those it's sometimes smart to fall down and then go in reverse direction, but lower/higher - SPECIAL; + SPECIAL { + @Override + public boolean isOpposite(ActionDirection direction) { + return false; + } + }; public static final ActionDirection[] VALUES = values(); - static { - NORTH.opposite = SOUTH; - SOUTH.opposite = NORTH; - EAST.opposite = WEST; - WEST.opposite = EAST; - NORTH_EAST.opposite = SOUTH_WEST; - NORTH_WEST.opposite = SOUTH_EAST; - SOUTH_EAST.opposite = NORTH_WEST; - SOUTH_WEST.opposite = NORTH_EAST; - UP.opposite = DOWN; - DOWN.opposite = UP; - SPECIAL.opposite = null; - } - - private ActionDirection opposite; + /** + * Checks if the given direction is the opposite of this direction. + * This also includes that the opposite of UP is DOWN and vice versa. + * It also includes diagonals, so NORTH_EAST is the opposite of SOUTH_WEST, + * but also the opposite of SOUTH and WEST. + * + * @param direction The direction to check + * @return If the given direction is the opposite of this direction + */ + public abstract boolean isOpposite(ActionDirection direction); }