Skip to content

Commit

Permalink
support killing the miner search thread
Browse files Browse the repository at this point in the history
  • Loading branch information
thiakil committed Sep 2, 2024
1 parent 59645a9 commit b2072ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void run() {
Block info;
BlockPos minerPos = tile.getBlockPos();
for (int i = 0; i < size; i++) {
if (tile.isRemoved()) {
if (tile.isRemoved() || isInterrupted()) {
//Make sure the miner is still valid and something hasn't gone wrong
return;
}
Expand Down Expand Up @@ -104,6 +104,9 @@ public void run() {

state = State.FINISHED;
chunkCache = null;
if (interrupted()) {
return;//no point checking as we got cancelled
}
if (tile.searcher == this) {
//Only update search if we are still valid and didn't get replaced due to a reset call
tile.updateFromSearch(oresToMine, found);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,9 @@ public void stop() {
}

public void reset() {
//TODO: Should the old searcher thread be terminated somehow?
if (searcher != null && searcher.isAlive()) {
searcher.interrupt();
}
searcher = new ThreadMinerSearch(this);
running = false;
cachedToMine = 0;
Expand Down

0 comments on commit b2072ca

Please sign in to comment.