From 47c7413215aa0ec30a93df9e367896d5ce648fea Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 2 Aug 2018 14:05:47 -0400 Subject: [PATCH] sanity check --- .../baritone/bot/pathing/action/Action.java | 8 ++++++ .../java/baritone/bot/pathing/calc/Path.java | 27 +++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/bot/pathing/action/Action.java b/src/main/java/baritone/bot/pathing/action/Action.java index 95455b06..56da0396 100644 --- a/src/main/java/baritone/bot/pathing/action/Action.java +++ b/src/main/java/baritone/bot/pathing/action/Action.java @@ -62,6 +62,14 @@ public abstract class Action implements AbstractGameEventListener, Helper, Actio && currentState.getStatus() != ActionStatus.WAITING); } + public BlockPos getSrc() { + return null; // TODO + } + + public BlockPos getDest() { + return null; // TODO + } + /** * Calculate latest action state. * Gets called once a tick. diff --git a/src/main/java/baritone/bot/pathing/calc/Path.java b/src/main/java/baritone/bot/pathing/calc/Path.java index 4bf9ac0e..beab6265 100644 --- a/src/main/java/baritone/bot/pathing/calc/Path.java +++ b/src/main/java/baritone/bot/pathing/calc/Path.java @@ -32,9 +32,13 @@ class Path implements IPath { this.path = new ArrayList<>(); this.actions = new ArrayList<>(); assemblePath(start, end); + sanityCheck(); } private final void assemblePath(PathNode start, PathNode end) { + if (!path.isEmpty() || !actions.isEmpty()) { + throw new IllegalStateException(); + } PathNode current = end; LinkedList tempPath = new LinkedList<>();//repeatedly inserting to the beginning of an arraylist is O(n^2) LinkedList tempActions = new LinkedList<>();//instead, do it into a linked list, then convert at the end @@ -51,8 +55,27 @@ class Path implements IPath { actions.addAll(tempActions); } - protected void sanityCheck() { - + public void sanityCheck() { + if (!start.equals(path.get(0))) { + throw new IllegalStateException(); + } + if (!end.equals(path.get(path.size() - 1))) { + throw new IllegalStateException(); + } + if (path.size() != actions.size() + 1) { + throw new IllegalStateException(); + } + for (int i = 0; i < path.size(); i++) { + BlockPos src = path.get(i); + BlockPos dest = path.get(i + 1); + Action action = actions.get(i); + if (!src.equals(action.getSrc())) { + throw new IllegalStateException(); + } + if (!dest.equals(action.getDest())) { + throw new IllegalStateException(); + } + } } @Override