Thanks for the reply, ahh right I see now what I was doing wrong and this looks exactly like what I should be doing. But even using that code it still continues the animation if someone else has mined the rock before my player. I added some extra code to try and get a better understand of what was going on:
if (rockToMine == null || !myPlayer().isAnimating() || !Rock.CLAY.hasOre(rockToMine)) {
rockToMine = getObjects().closest(object -> Rock.CLAY.hasOre(object));
if (rockToMine != null && rockToMine.interact("Mine")) {
new ConditionalSleep(3000, 1000) {
@Override
public boolean condition() throws InterruptedException {
if (!Rock.CLAY.hasOre(rockToMine)) {
log("Rock has no ore!");
return true;
} else if (!myPlayer().isAnimating()) {
log("Animation finished!");
return true;
} else {
return false;
}
}
}.sleep();
}
}
When checking the log, the "Rock has no ore!" never appears, which is confusing as I have watched the bot in times when the rock is empty of ore and the animation is still continuing regardless, it never reaches the "Rock has no ore!" output, just only ever outputting "Animation finished", whenever the animation has finished.
I also changed the sleep conditional return to myPlayer().isAnimating() to !myPlayer().isAnimating() as wouldn't I want it to return true if the player had stopped animating, to break the sleep conditional?