Skip to content

Commit

Permalink
Merge pull request #31 from Intybyte/opt/DistillRunnable
Browse files Browse the repository at this point in the history
Opt/distill runnable
  • Loading branch information
Jsinco authored Aug 31, 2024
2 parents 43afb90 + 4940e7d commit 2cc1a35
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions src/main/java/com/dre/brewery/BDistiller.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,41 +176,40 @@ public class DistillRunnable extends UniversalRunnable {
@Override
public void run() {
BreweryPlugin.getScheduler().runTask(standBlock.getLocation(), () -> {
BlockState now = standBlock.getState();
if (now instanceof BrewingStand stand) {
if (brewTime == -1) { // check at the beginning for distillables
if (!prepareForDistillables(stand)) {
return;
}
}
if (standBlock.getType() != Material.BREWING_STAND) {
this.cancel();
trackedDistillers.remove(standBlock);
BreweryPlugin.getInstance().debugLog("The block was replaced; not a brewing stand.");
return;
}

brewTime--; // count down.
stand.setBrewingTime((int) ((float) brewTime / ((float) runTime / (float) DISTILLTIME)) + 1);
BrewingStand stand = (BrewingStand) standBlock.getState();
if (brewTime == -1 && !prepareForDistillables(stand)) { // check at the beginning for distillables
return;
}

if (brewTime <= 1) { // Done!
contents = getDistillContents(stand.getInventory()); // Get the contents again at the end just in case
stand.setBrewingTime(0);
stand.update();
if (!runDistill(stand.getInventory(), contents)) {
this.cancel();
trackedDistillers.remove(standBlock);
BreweryPlugin.getInstance().debugLog("All done distilling");
} else {
brewTime = -1; // go again.
BreweryPlugin.getInstance().debugLog("Can distill more! Continuing.");
}
} else {
stand.update();
}
} else {
brewTime--; // count down.
stand.setBrewingTime((int) ((float) brewTime / ((float) runTime / (float) DISTILLTIME)) + 1);

if (brewTime > 1) {
stand.update();
return;
}

contents = getDistillContents(stand.getInventory()); // Get the contents again at the end just in case
stand.setBrewingTime(0);
stand.update();
if (!runDistill(stand.getInventory(), contents)) {
this.cancel();
trackedDistillers.remove(standBlock);
BreweryPlugin.getInstance().debugLog("The block was replaced; not a brewing stand.");
BreweryPlugin.getInstance().debugLog("All done distilling");
} else {
brewTime = -1; // go again.
BreweryPlugin.getInstance().debugLog("Can distill more! Continuing.");
}
});
}


private boolean prepareForDistillables(BrewingStand stand) {
BrewerInventory inventory = stand.getInventory();
if (contents == null) {
Expand Down

0 comments on commit 2cc1a35

Please sign in to comment.