Yes it is a problem in the CHOP case as I stated.
Invoking interact() on an Entity will create a default InteractionEvent instance which will walk to that Entity if it's too far. InteractionEvent will create a WalkingEvent instance and set it as its child. This WalkingEvent instance will create a LocalPathFinder instance that will generate a path to the closest position from which the target of the InteractionEvent can be accessed.
The problem in here is that LocalPathFinder will only generate paths to tiles that are on map, which results in this weird behavior depending on how the current region loaded. Those entities that are not on minimap cannot be walked to, but they are not null so your bot will be stuck there trying to find a path to it.
case CHOP:
Entity treeToChop = objects.closest(tree);
GroundItem birdNest = groundItems.closest("Bird nest");
treeToChop.interact("Chop down");
StatusUpdate = "Chopping " + tree + " logs";
new ConditionalSleep(10000) {
public boolean condition() throws InterruptedException {
return !treeToChop.exists();
}
}.sleep();
if (birdNest != null && pickupBirdsNests == true) {
birdNest.interact("Take");
}
break;
Adjusted some code in there. You already null check the tree in your getState() so the if is redundant. There are many ways to check to check if you can walk to that specific Entity, easiest would be
private State getState() {
Entity treeToChop = objects.closest(tree);
if (inventory.isFull() && powerChop == false)
return State.BANK;
if(inventory.isFull() && powerChop == true)
return State.POWERCHOP;
if (treeToChop != null && map.canReach(treeToChop))
return State.CHOP;
else
return State.WALK;
}
You can also go with
LocalPathFinder lpf = new LocalPathFinder(bot);
lpf.findPath(tree);
And use
lpf.foundPath()
As condition to verify if you can walk to your tree.
tree.getPosition().isOnMiniMap(bot)
Is good but not perfect, it leaves out the 1 in a million case where trees are arranged in such way that the tree is on minimap, but there is no tile on minimap from which you can access it