Fixes to the Brewing Stand for distilling

This commit is contained in:
Sn0wStorm 2018-10-31 20:22:48 +01:00
parent db61e27fa3
commit 0ed69b7125
4 changed files with 26 additions and 10 deletions

View File

@ -2,6 +2,7 @@ package com.dre.brewery;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Levelled;
import org.bukkit.entity.Player;
import org.bukkit.Material;
@ -97,12 +98,17 @@ public class BCauldron {
if (potion != null) {
if (P.use1_13) {
Levelled cauldron = ((Levelled) block.getBlockData());
BlockData data = block.getBlockData();
Levelled cauldron = ((Levelled) data);
if (cauldron.getLevel() <= 0) {
bcauldrons.remove(bcauldron);
return false;
}
cauldron.setLevel(cauldron.getLevel() - 1);
// Update the new Level to the Block
// We have to use the BlockData variable "data" here instead of the casted "cauldron"
// otherwise < 1.13 crashes on plugin load for not finding the BlockData Class
block.setBlockData(data);
if (cauldron.getLevel() <= 0) {
bcauldrons.remove(bcauldron);

View File

@ -727,10 +727,12 @@ public class Brew {
public void colorBrew(PotionMeta meta, ItemStack potion, boolean destillable) {
if (P.use1_9) {
meta.setBasePotionData(new PotionData(getType()));
meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
if (P.use1_12) {
// BasePotionData was only used for the Color, so starting with 1.12 we can use setColor instead
meta.setColor(getColor());
} else {
meta.setBasePotionData(new PotionData(getType()));
}
} else {
potion.setDurability(getColorId(destillable));

View File

@ -124,11 +124,18 @@ public class InventoryListener implements Listener {
case 1:
// Custom potion but not for distilling. Stop any brewing and cancel this task
if (stand.getBrewingTime() > 0) {
// Brewing time is sent and stored as short
// This sends a negative short value to the Client
// In the client the Brewer will look like it is not doing anything
stand.setBrewingTime(Short.MAX_VALUE << 1);
if (P.use1_12) {
// The trick below doesnt work in 1.12, but we dont need it anymore
// This should only happen with older Brews that have been made with the old Potion Color System
stand.setBrewingTime(Short.MAX_VALUE);
} else {
// Brewing time is sent and stored as short
// This sends a negative short value to the Client
// In the client the Brewer will look like it is not doing anything
stand.setBrewingTime(Short.MAX_VALUE << 1);
}
stand.setFuelLevel(fuel);
stand.update();
}
case 0:
// No custom potion, cancel and ignore
@ -148,19 +155,20 @@ public class InventoryListener implements Listener {
stand.setBrewingTime((int) ((float) brewTime / ((float) runTime / (float) DISTILLTIME)) + 1);
if (brewTime <= 1) { // Done!
stand.setBrewingTime(0);
stand.update();
BrewerInventory brewer = stand.getInventory();
if (!runDistill(brewer)) {
this.cancel();
trackedBrewers.remove(brewery);
stand.setBrewingTime(0);
P.p.debugLog("All done distilling");
} else {
brewTime = -1; // go again.
stand.setBrewingTime(0);
P.p.debugLog("Can distill more! Continuing.");
}
} else {
stand.update();
}
stand.update();
} else {
this.cancel();
trackedBrewers.remove(brewery);

View File

@ -17,7 +17,7 @@ public class TabListener implements TabCompleter {
private static final List<String> topCompletions = new ArrayList<>(2);
static {
completions.put("", Arrays.asList("info", "unlabel"));
completions.put("", Arrays.asList("info", "unlabel", "help"));
topCompletions.add("brew");
//topCompletions.add("brewery");
}