diff --git a/resources/config/de/config.yml b/resources/config/de/config.yml index efe3291..06b6768 100644 --- a/resources/config/de/config.yml +++ b/resources/config/de/config.yml @@ -79,6 +79,7 @@ version: '1.5' # Vault erkennt Namen wie "Jungle Leaves" anstatt "LEAVES,3". Dies macht es viel einfacher! # cookingtime: Zeit in Echtminuten die die Zutaten kochen müssen # distillruns: Wie oft destilliert werden muss für vollen Alkoholgehalt (0=ohne Destillieren) +# distilltime: Wie lange (in sekunden) ein Destillations-Durchlauf braucht (0=Standard Zeit von 40 sek) MC Standard wäre 20 sek # wood: Holz des Fasses 0=alle Holzsorten 1=Birke 2=Eiche 3=Jungel 4=Fichte 5=Akazie 6=Schwarzeiche # age: Zeit in Minecraft-Tagen, die das Getränk im Fass reifen muss 0= kein reifen # color: Farbe des Getränks nach destillieren/reifen. @@ -107,6 +108,7 @@ recipes: # - Green Dye/6 # Nur mit Vault cookingtime: 3 distillruns: 2 + distilltime: 60 wood: 4 age: 11 color: DARK_RED @@ -181,6 +183,7 @@ recipes: - SUGAR_CANE/14 cookingtime: 5 distillruns: 2 + distilltime: 30 wood: 2 age: 14 color: DARK_RED @@ -208,6 +211,7 @@ recipes: - LONG_GRASS/15 cookingtime: 3 distillruns: 6 + distilltime: 80 color: GREEN difficulty: 8 alcohol: 45 diff --git a/resources/config/en/config.yml b/resources/config/en/config.yml index 09830f3..2460954 100644 --- a/resources/config/en/config.yml +++ b/resources/config/en/config.yml @@ -76,6 +76,7 @@ version: '1.5' # Vault will recognize things like "Jungle Leaves" instead of "LEAVES,3" # cookingtime: Time in real minutes ingredients have to boil # distillruns: How often it has to be distilled for full alcohol (0=without distilling) +# distilltime: How long (in seconds) one distill-run takes (0=Default time of 40 sec) MC Default would be 20 sec # wood: Wood of the barrel 0=any 1=Birch 2=Oak 3=Jungle 4=Spruce 5=Acacia 6=Dark Oak # age: Time in Minecraft-days, the potion has to age in a barrel 0=no aging # color: Color of the potion after distilling/aging. @@ -104,6 +105,7 @@ recipes: # - Green Dye/6 # Only with Vault cookingtime: 3 distillruns: 2 + distilltime: 60 wood: 4 age: 11 color: DARK_RED @@ -178,6 +180,7 @@ recipes: - SUGAR_CANE/14 cookingtime: 5 distillruns: 2 + distilltime: 30 wood: 2 age: 14 color: DARK_RED @@ -205,6 +208,7 @@ recipes: - LONG_GRASS/15 cookingtime: 3 distillruns: 6 + distilltime: 80 color: GREEN difficulty: 8 alcohol: 45 diff --git a/resources/config/fr/config.yml b/resources/config/fr/config.yml index 233899a..e9d83d7 100644 --- a/resources/config/fr/config.yml +++ b/resources/config/fr/config.yml @@ -77,6 +77,7 @@ version: '1.5' # Vault will recognize things like "Jungle Leaves" instead of "5,3" # cookingtime: Temps en minutes réelles durant lesquelles les ingrédients devront bouillir # distillruns: Combien de fois le breuvage devra être distillé pour un alcool de qualité (0=Ne pas distiller) +# distilltime: How long (in seconds) one distill-run takes (0=Default time of 40 sec) MC Default would be 20 sec # wood: Type de bois du baril 0=aucun 1=Bouleau 2=Chêne 3=Jungle 4=Pin 5=Acacia 6=Chêne Noir # age: Temps en jours de Minecraft, la potion devra être âgée dans un baril. 0=Pas besoin d'âge # color: Couleur de la potion après distillation/avoir laissé vieillir. @@ -109,6 +110,7 @@ recipes: # - Green Dye/6 # Only with Vault cookingtime: 3 distillruns: 2 + distilltime: 60 wood: 4 age: 11 color: DARK_RED @@ -183,6 +185,7 @@ recipes: - SUGAR_CANE/14 cookingtime: 5 distillruns: 2 + distilltime: 30 wood: 2 age: 14 color: DARK_RED @@ -210,6 +213,7 @@ recipes: - LONG_GRASS/15 cookingtime: 3 distillruns: 6 + distilltime: 80 color: GREEN difficulty: 8 alcohol: 45 diff --git a/resources/config/it/config.yml b/resources/config/it/config.yml index 753d57f..591a76b 100755 --- a/resources/config/it/config.yml +++ b/resources/config/it/config.yml @@ -76,6 +76,7 @@ version: '1.5' # Vault riconoscerà cose come "Jungle Leaves" invece di "LEAVES,3". # cookingtime: Tempo in minuti richiesto dagli ingredienti per bollire # distillruns: Quanto spesso deve essere distillato per ottenere la versione perfetta con il volume alcolico impostato (0=non serve distillare). +# distilltime: How long (in seconds) one distill-run takes (0=Default time of 40 sec) MC Default would be 20 sec # wood: Legno del barile 0=qualiasi 1=Betulla 2=Quercia 3=Mogano 4=Abete 5=Acacia 6=Quercia nera # age: Tempo in giorni di Minecraft per cui la pozione deve essere invecchiata in un barile (0=nessun invecchiamento). # color: Colore della pozione dopo essere stata distillata/invecchiata @@ -104,6 +105,7 @@ recipes: # - Green Dye/6 # Solo con Vault cookingtime: 3 distillruns: 2 + distilltime: 60 wood: 4 age: 11 color: DARK_RED @@ -178,6 +180,7 @@ recipes: - SUGAR_CANE/14 cookingtime: 5 distillruns: 2 + distilltime: 30 wood: 2 age: 14 color: DARK_RED @@ -205,6 +208,7 @@ recipes: - LONG_GRASS/15 cookingtime: 3 distillruns: 6 + distilltime: 80 color: GREEN difficulty: 8 alcohol: 45 diff --git a/src/com/dre/brewery/BRecipe.java b/src/com/dre/brewery/BRecipe.java index d75f51c..22830f3 100644 --- a/src/com/dre/brewery/BRecipe.java +++ b/src/com/dre/brewery/BRecipe.java @@ -12,14 +12,15 @@ import java.util.List; public class BRecipe { private String[] name; - private ArrayList ingredients = new ArrayList<>();// material and amount - private int cookingTime;// time to cook in cauldron - private int distillruns;// runs through the brewer - private byte wood;// type of wood the barrel has to consist of - private int age;// time in minecraft days for the potions to age in barrels - private String color;// color of the destilled/finished potion - private int difficulty;// difficulty to brew the potion, how exact the instruction has to be followed - private int alcohol;// Alcohol in perfect potion + private ArrayList ingredients = new ArrayList<>(); // material and amount + private int cookingTime; // time to cook in cauldron + private int distillruns; // runs through the brewer + private int distillTime; // time for one distill run in seconds + private byte wood; // type of wood the barrel has to consist of + private int age; // time in minecraft days for the potions to age in barrels + private String color; // color of the destilled/finished potion + private int difficulty; // difficulty to brew the potion, how exact the instruction has to be followed + private int alcohol; // Alcohol in perfect potion private ArrayList effects = new ArrayList<>(); // Special Effects when drinking public BRecipe(ConfigurationSection configSectionRecipes, String recipeId) { @@ -88,13 +89,14 @@ public class BRecipe { } } } - this.cookingTime = configSectionRecipes.getInt(recipeId + ".cookingtime"); - this.distillruns = configSectionRecipes.getInt(recipeId + ".distillruns"); - this.wood = (byte) configSectionRecipes.getInt(recipeId + ".wood"); - this.age = configSectionRecipes.getInt(recipeId + ".age"); + this.cookingTime = configSectionRecipes.getInt(recipeId + ".cookingtime", 1); + this.distillruns = configSectionRecipes.getInt(recipeId + ".distillruns", 0); + this.distillTime = configSectionRecipes.getInt(recipeId + ".distilltime", 0) * 20; + this.wood = (byte) configSectionRecipes.getInt(recipeId + ".wood", 0); + this.age = configSectionRecipes.getInt(recipeId + ".age", 0); this.color = configSectionRecipes.getString(recipeId + ".color"); - this.difficulty = configSectionRecipes.getInt(recipeId + ".difficulty"); - this.alcohol = configSectionRecipes.getInt(recipeId + ".alcohol"); + this.difficulty = configSectionRecipes.getInt(recipeId + ".difficulty", 0); + this.alcohol = configSectionRecipes.getInt(recipeId + ".alcohol", 0); List effectStringList = configSectionRecipes.getStringList(recipeId + ".effects"); if (effectStringList != null) { @@ -131,6 +133,10 @@ public class BRecipe { P.p.errorLog("Invalid distillruns '" + distillruns + "' in Recipe: " + getName(5)); return false; } + if (distillTime < 0) { + P.p.errorLog("Invalid distilltime '" + distillTime + "' in Recipe: " + getName(5)); + return false; + } if (wood < 0 || wood > 6) { P.p.errorLog("Invalid wood type '" + wood + "' in Recipe: " + getName(5)); return false; @@ -316,6 +322,10 @@ public class BRecipe { return distillruns; } + public int getDistillTime() { + return distillTime; + } + public String getColor() { if (color != null) { return color.toUpperCase(); diff --git a/src/com/dre/brewery/Brew.java b/src/com/dre/brewery/Brew.java index 19d74df..3c28035 100644 --- a/src/com/dre/brewery/Brew.java +++ b/src/com/dre/brewery/Brew.java @@ -329,16 +329,13 @@ public class Brew { // Distilling section --------------- // distill all custom potions in the brewer - public static void distillAll(BrewerInventory inv, Boolean[] contents) { - int slot = 0; - while (slot < 3) { - if (contents[slot]) { + public static void distillAll(BrewerInventory inv, Brew[] contents) { + for (int slot = 0; slot < 3; slot++) { + if (contents[slot] != null) { ItemStack slotItem = inv.getItem(slot); PotionMeta potionMeta = (PotionMeta) slotItem.getItemMeta(); - Brew brew = get(potionMeta); - brew.distillSlot(slotItem, potionMeta); + contents[slot].distillSlot(slotItem, potionMeta); } - slot++; } } @@ -382,6 +379,22 @@ public class Brew { slotItem.setItemMeta(potionMeta); } + public int getDistillTimeNextRun() { + if (!canDistill()) { + return -1; + } + + if (currentRecipe != null) { + return currentRecipe.getDistillTime(); + } + + BRecipe recipe = ingredients.getdistillRecipe(wood, ageTime); + if (recipe != null) { + return recipe.getDistillTime(); + } + return 0; + } + // Ageing Section ------------------ public void age(ItemStack item, float time, byte woodType) { diff --git a/src/com/dre/brewery/filedata/ConfigUpdater.java b/src/com/dre/brewery/filedata/ConfigUpdater.java index 32b21a8..c168846 100644 --- a/src/com/dre/brewery/filedata/ConfigUpdater.java +++ b/src/com/dre/brewery/filedata/ConfigUpdater.java @@ -950,6 +950,35 @@ public class ConfigUpdater { addLines(index, lines); } } + + lines = new String[] {"# distilltime: Wie lange (in sekunden) ein Destillations-Durchlauf braucht (0=Standard Zeit von 40 sek) MC Standard wäre 20 sek"}; + + index = indexOfStart("# distillruns:"); + if (index == -1) { + index = indexOfStart("# wood:") - 1; + if (index == -2) { + index = indexOfStart("# -- Rezepte") + 1; + if (index == 0) { + index = -1; + } + } + } + if (index != -1) { + addLines(index + 1, lines); + } + + index = indexOfStart(" name: Schlechtes Beispiel/Beispiel/Gutes Beispiel"); + if (index != -1) { + addLines(index + 1, " distilltime: 60"); + } + index = indexOfStart(" name: Bitterer Rum/Würziger Rum/&6Goldener Rum"); + if (index != -1) { + addLines(index + 1, " distilltime: 30"); + } + index = indexOfStart(" name: minderwertiger Absinth/Absinth/Starker Absinth"); + if (index != -1) { + addLines(index + 1, " distilltime: 80"); + } } // Update de from 1.4 to 1.5 @@ -993,6 +1022,35 @@ public class ConfigUpdater { addLines(index, lines); } } + + lines = new String[] {"# distilltime: How long (in seconds) one distill-run takes (0=Default time of 40 sec) MC Default would be 20 sec"}; + + index = indexOfStart("# distillruns:"); + if (index == -1) { + index = indexOfStart("# wood:") - 1; + if (index == -2) { + index = indexOfStart("# -- Recipes") + 1; + if (index == 0) { + index = -1; + } + } + } + if (index != -1) { + addLines(index + 1, lines); + } + + index = indexOfStart(" name: Bad Example/Example/Good Example"); + if (index != -1) { + addLines(index + 1, " distilltime: 60"); + } + index = indexOfStart(" name: Bitter Rum/Spicy Rum/&6Golden Rum"); + if (index != -1) { + addLines(index + 1, " distilltime: 30"); + } + index = indexOfStart(" name: Poor Absinthe/Absinthe/Strong Absinthe"); + if (index != -1) { + addLines(index + 1, " distilltime: 80"); + } } diff --git a/src/com/dre/brewery/listeners/InventoryListener.java b/src/com/dre/brewery/listeners/InventoryListener.java index 813b2fd..a5e45a9 100644 --- a/src/com/dre/brewery/listeners/InventoryListener.java +++ b/src/com/dre/brewery/listeners/InventoryListener.java @@ -37,7 +37,7 @@ public class InventoryListener implements Listener { /* === Recreating manually the prior BrewEvent behavior. === */ private HashSet trackedBrewmen = new HashSet<>(); private HashMap trackedBrewers = new HashMap<>(); - private static final int DISTILLTIME = 401; + private static final int DISTILLTIME = 400; /** * Start tracking distillation for a person when they open the brewer window. @@ -69,6 +69,15 @@ public class InventoryListener implements Listener { trackedBrewmen.remove(player.getUniqueId()); } + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void onBrewerDrag(InventoryDragEvent event) { + if (!P.use1_9) return; + // Workaround the Drag event when only clicking a slot + if (event.getInventory() instanceof BrewerInventory) { + onBrewerClick(new InventoryClickEvent(event.getView(), InventoryType.SlotType.CONTAINER, 0, ClickType.LEFT, InventoryAction.PLACE_ALL)); + } + } + /** * Clicking can either start or stop the new brew distillation tracking. * Note that server restart will halt any ongoing brewing processes and @@ -102,13 +111,14 @@ public class InventoryListener implements Listener { // Now check if we should bother to track it. trackedBrewers.put(brewery, new BukkitRunnable() { - private int brewTime = DISTILLTIME; + private int runTime = -1; + private int brewTime = -1; @Override public void run() { BlockState now = brewery.getState(); if (now instanceof BrewingStand) { BrewingStand stand = (BrewingStand) now; - if (brewTime == DISTILLTIME) { // only check at the beginning (and end) for distillables + if (brewTime == -1) { // only check at the beginning (and end) for distillables switch (hasCustom(stand.getInventory())) { case 1: // Custom potion but not for distilling. Stop any brewing and cancel this task @@ -126,12 +136,15 @@ public class InventoryListener implements Listener { P.p.debugLog("nothing to distill"); return; default: + runTime = getLongestDistillTime(stand.getInventory()); + brewTime = runTime; + P.p.log("using brewtime: " + runTime); } } brewTime--; // count down. - stand.setBrewingTime(brewTime); // arbitrary for now + stand.setBrewingTime((int) ((float) brewTime / ((float) runTime / (float) DISTILLTIME)) + 1); if (brewTime <= 1) { // Done! BrewerInventory brewer = stand.getInventory(); @@ -141,7 +154,8 @@ public class InventoryListener implements Listener { stand.setBrewingTime(0); P.p.debugLog("All done distilling"); } else { - brewTime = DISTILLTIME; // go again. + brewTime = -1; // go again. + stand.setBrewingTime(0); P.p.debugLog("Can distill more! Continuing."); } } @@ -154,35 +168,39 @@ public class InventoryListener implements Listener { }.runTaskTimer(P.p, 2L, 1L).getTaskId()); } + // Returns a Brew or null for every Slot in the BrewerInventory + private Brew[] getDistillContents(BrewerInventory inv) { + ItemStack item; + Brew[] contents = new Brew[3]; + for (int slot = 0; slot < 3; slot++) { + item = inv.getItem(slot); + if (item != null) { + contents[slot] = Brew.get(item); + } + } + return contents; + } + private byte hasCustom(BrewerInventory brewer) { ItemStack item = brewer.getItem(3); // ingredient boolean glowstone = (item != null && Material.GLOWSTONE_DUST == item.getType()); // need dust in the top slot. byte customFound = 0; - for (int slot = 0; slot < 3; slot++) { - item = brewer.getItem(slot); - if (item != null) { - if (item.getType() == Material.POTION) { - if (item.hasItemMeta()) { - int uid = Brew.getUID(item); - Brew pot = Brew.potions.get(uid); - if (pot != null) { - if (!glowstone) { - return 1; - } - if (pot.canDistill()) { - return 2; - } else { - customFound = 1; - } - } - } + for (Brew brew : getDistillContents(brewer)) { + if (brew != null) { + if (!glowstone) { + return 1; + } + if (brew.canDistill()) { + return 2; + } else { + customFound = 1; } } } return customFound; } - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onBrew(BrewEvent event) { if (P.use1_9) { if (hasCustom(event.getContents()) != 0) { @@ -196,29 +214,16 @@ public class InventoryListener implements Listener { } private boolean runDistill(BrewerInventory inv) { - int slot = 0; - ItemStack item; boolean custom = false; - Boolean[] contents = new Boolean[3]; - while (slot < 3) { - item = inv.getItem(slot); - contents[slot] = false; - if (item != null) { - if (item.getType() == Material.POTION) { - if (item.hasItemMeta()) { - int uid = Brew.getUID(item); - if (Brew.potions.containsKey(uid)) { - // has custom potion in "slot" - if (Brew.get(uid).canDistill()) { - // is further distillable - contents[slot] = true; - custom = true; - } - } - } - } + Brew[] contents = getDistillContents(inv); + for (int slot = 0; slot < 3; slot++) { + if (contents[slot] == null) continue; + if (contents[slot].canDistill()) { + // is further distillable + custom = true; + } else { + contents[slot] = null; } - slot++; } if (custom) { Brew.distillAll(inv, contents); @@ -227,6 +232,27 @@ public class InventoryListener implements Listener { return false; } + private int getLongestDistillTime(BrewerInventory inv) { + int bestTime = 0; + int time = 0; + Brew[] contents = getDistillContents(inv); + for (int slot = 0; slot < 3; slot++) { + if (contents[slot] == null) continue; + time = contents[slot].getDistillTimeNextRun(); + if (time == 0) { + // Undefined Potion needs 40 seconds + time = 800; + } + if (time > bestTime) { + bestTime = time; + } + } + if (bestTime > 0) { + return bestTime; + } + return 800; + } + // Clicked a Brew somewhere, do some updating @EventHandler(priority = EventPriority.LOW, ignoreCancelled = false) public void onInventoryClickLow(InventoryClickEvent event) {