Some BDistiller cleanup

This commit is contained in:
Sn0wStorm 2020-11-02 17:12:15 +01:00
parent c474ccb9dd
commit 95f59a5982

View File

@ -89,7 +89,7 @@ public class BDistiller {
for (int slot = 0; slot < 3; slot++) {
if (contents[slot] != null) {
item = inv.getItem(slot);
if (item == null || !Brew.isBrew(item)) {
if (!Brew.isBrew(item)) {
contents[slot] = null;
}
}
@ -168,7 +168,7 @@ public class BDistiller {
}
public class DistillRunnable extends BukkitRunnable {
Brew[] contents = null;
private Brew[] contents = null;
@Override
public void run() {
@ -176,6 +176,35 @@ public class BDistiller {
if (now instanceof BrewingStand) {
BrewingStand stand = (BrewingStand) now;
if (brewTime == -1) { // only check at the beginning (and end) for distillables
prepareForDistillables(stand);
}
brewTime--; // count down.
stand.setBrewingTime((int) ((float) brewTime / ((float) runTime / (float) DISTILLTIME)) + 1);
if (brewTime <= 1) { // Done!
checkContents(stand.getInventory(), contents);
stand.setBrewingTime(0);
stand.update();
if (!runDistill(stand.getInventory(), contents)) {
this.cancel();
trackedDistillers.remove(standBlock);
P.p.debugLog("All done distilling");
} else {
brewTime = -1; // go again.
P.p.debugLog("Can distill more! Continuing.");
}
} else {
stand.update();
}
} else {
this.cancel();
trackedDistillers.remove(standBlock);
P.p.debugLog("The block was replaced; not a brewing stand.");
}
}
private void prepareForDistillables(BrewingStand stand) {
BrewerInventory inventory = stand.getInventory();
if (contents == null) {
contents = getDistillContents(inventory);
@ -213,30 +242,5 @@ public class BDistiller {
}
}
brewTime--; // count down.
stand.setBrewingTime((int) ((float) brewTime / ((float) runTime / (float) DISTILLTIME)) + 1);
if (brewTime <= 1) { // Done!
checkContents(stand.getInventory(), contents);
stand.setBrewingTime(0);
stand.update();
if (!runDistill(stand.getInventory(), contents)) {
this.cancel();
trackedDistillers.remove(standBlock);
P.p.debugLog("All done distilling");
} else {
brewTime = -1; // go again.
P.p.debugLog("Can distill more! Continuing.");
}
} else {
stand.update();
}
} else {
this.cancel();
trackedDistillers.remove(standBlock);
P.p.debugLog("The block was replaced; not a brewing stand.");
}
}
}
}