mirror of
https://github.com/exituser/Brewery.git
synced 2026-09-17 06:38:56 +00:00
Fixed Distilling
This commit is contained in:
@@ -57,7 +57,7 @@ public class BIngredients {
|
|||||||
|
|
||||||
if (cookRecipe != null) {
|
if (cookRecipe != null) {
|
||||||
// Potion is best with cooking only, can still be destilled, etc.
|
// Potion is best with cooking only, can still be destilled, etc.
|
||||||
int quality = (int) Math.round((getIngredientQuality(cookRecipe) + getCookingQuality(cookRecipe)) / 2.0);
|
int quality = (int) Math.round((getIngredientQuality(cookRecipe) + getCookingQuality(cookRecipe, false)) / 2.0);
|
||||||
P.p.log("cooked potion has Quality: " + quality);
|
P.p.log("cooked potion has Quality: " + quality);
|
||||||
new Brew(uid, quality, cookRecipe, new BIngredients(ingredients, cookedTime));
|
new Brew(uid, quality, cookRecipe, new BIngredients(ingredients, cookedTime));
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ public class BIngredients {
|
|||||||
|
|
||||||
// best recipe for current state of potion, STILL not always returns the
|
// best recipe for current state of potion, STILL not always returns the
|
||||||
// correct one...
|
// correct one...
|
||||||
public BRecipe getBestRecipe(byte wood, float time) {
|
public BRecipe getBestRecipe(byte wood, float time, boolean distilled) {
|
||||||
float quality = 0;
|
float quality = 0;
|
||||||
int ingredientQuality = 0;
|
int ingredientQuality = 0;
|
||||||
int cookingQuality = 0;
|
int cookingQuality = 0;
|
||||||
@@ -127,7 +127,7 @@ public class BIngredients {
|
|||||||
BRecipe bestRecipe = null;
|
BRecipe bestRecipe = null;
|
||||||
for (BRecipe recipe : recipes) {
|
for (BRecipe recipe : recipes) {
|
||||||
ingredientQuality = getIngredientQuality(recipe);
|
ingredientQuality = getIngredientQuality(recipe);
|
||||||
cookingQuality = getCookingQuality(recipe);
|
cookingQuality = getCookingQuality(recipe, distilled);
|
||||||
|
|
||||||
if (ingredientQuality > -1) {
|
if (ingredientQuality > -1) {
|
||||||
P.p.log("Ingredient Quality: " + ingredientQuality + " Cooking Quality: " + cookingQuality + " Wood Quality: " + getWoodQuality(recipe, wood) + " age Quality: "
|
P.p.log("Ingredient Quality: " + ingredientQuality + " Cooking Quality: " + cookingQuality + " Wood Quality: " + getWoodQuality(recipe, wood) + " age Quality: "
|
||||||
@@ -160,7 +160,7 @@ public class BIngredients {
|
|||||||
// returns recipe that is cooking only and matches the ingredients and
|
// returns recipe that is cooking only and matches the ingredients and
|
||||||
// cooking time
|
// cooking time
|
||||||
public BRecipe getCookRecipe() {
|
public BRecipe getCookRecipe() {
|
||||||
BRecipe bestRecipe = getBestRecipe((byte) 0, 0);
|
BRecipe bestRecipe = getBestRecipe((byte) 0, 0, false);
|
||||||
|
|
||||||
// Check if best recipe is cooking only
|
// Check if best recipe is cooking only
|
||||||
if (bestRecipe != null) {
|
if (bestRecipe != null) {
|
||||||
@@ -174,7 +174,7 @@ public class BIngredients {
|
|||||||
// returns the currently best matching recipe for distilling for the
|
// returns the currently best matching recipe for distilling for the
|
||||||
// ingredients and cooking time
|
// ingredients and cooking time
|
||||||
public BRecipe getdistillRecipe() {
|
public BRecipe getdistillRecipe() {
|
||||||
BRecipe bestRecipe = getBestRecipe((byte) 0, 0);
|
BRecipe bestRecipe = getBestRecipe((byte) 0, 0, true);
|
||||||
|
|
||||||
// Check if best recipe needs to be destilled
|
// Check if best recipe needs to be destilled
|
||||||
if (bestRecipe != null) {
|
if (bestRecipe != null) {
|
||||||
@@ -187,8 +187,8 @@ public class BIngredients {
|
|||||||
|
|
||||||
// returns currently best matching recipe for ingredients, cooking- and
|
// returns currently best matching recipe for ingredients, cooking- and
|
||||||
// ageingtime
|
// ageingtime
|
||||||
public BRecipe getAgeRecipe(byte wood, float time) {
|
public BRecipe getAgeRecipe(byte wood, float time, boolean distilled) {
|
||||||
BRecipe bestRecipe = getBestRecipe(wood, time);
|
BRecipe bestRecipe = getBestRecipe(wood, time, distilled);
|
||||||
|
|
||||||
if (bestRecipe != null) {
|
if (bestRecipe != null) {
|
||||||
if (bestRecipe.needsToAge()) {
|
if (bestRecipe.needsToAge()) {
|
||||||
@@ -240,7 +240,10 @@ public class BIngredients {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// returns the quality regarding the cooking-time conditioning given Recipe
|
// returns the quality regarding the cooking-time conditioning given Recipe
|
||||||
public int getCookingQuality(BRecipe recipe) {
|
public int getCookingQuality(BRecipe recipe, boolean distilled) {
|
||||||
|
if (!recipe.needsDistilling() == distilled) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int quality = 10 - (int) Math.round(((float) Math.abs(cookedTime - recipe.getCookingTime()) / recipe.allowedTimeDiff(recipe.getCookingTime())) * 10.0);
|
int quality = 10 - (int) Math.round(((float) Math.abs(cookedTime - recipe.getCookingTime()) / recipe.allowedTimeDiff(recipe.getCookingTime())) * 10.0);
|
||||||
|
|
||||||
if (quality > 0) {
|
if (quality > 0) {
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ public class Barrel {
|
|||||||
if (inventory.getViewers().isEmpty()) {
|
if (inventory.getViewers().isEmpty()) {
|
||||||
// if inventory contains potions
|
// if inventory contains potions
|
||||||
if (inventory.contains(373)) {
|
if (inventory.contains(373)) {
|
||||||
|
long loadTime = System.nanoTime();
|
||||||
for (ItemStack item : inventory.getContents()) {
|
for (ItemStack item : inventory.getContents()) {
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
if (item.getTypeId() == 373) {
|
if (item.getTypeId() == 373) {
|
||||||
@@ -88,6 +89,9 @@ public class Barrel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
loadTime = System.nanoTime() - loadTime;
|
||||||
|
float ftime = (float) (loadTime / 1000000.0);
|
||||||
|
P.p.log("opening Barrel with potions (" + ftime + "ms)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,8 +112,11 @@ public class Brew {
|
|||||||
if (currentRecipe != null) {
|
if (currentRecipe != null) {
|
||||||
int alc = currentRecipe.getAlcohol();
|
int alc = currentRecipe.getAlcohol();
|
||||||
alc *= ((float) quality / 10.0);
|
alc *= ((float) quality / 10.0);
|
||||||
if (distillRuns > 1) {
|
if (currentRecipe.needsDistilling()) {
|
||||||
alc *= (float) distillRuns / 2.0;
|
// distillable Potions should have full alc after 6 distills
|
||||||
|
float factor = 1.4F / (distillRuns + 1);
|
||||||
|
factor += 0.8;
|
||||||
|
alc /= factor;
|
||||||
}
|
}
|
||||||
return alc;
|
return alc;
|
||||||
}
|
}
|
||||||
@@ -121,12 +124,12 @@ public class Brew {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// calculating quality
|
// calculating quality
|
||||||
public int calcQuality(BRecipe recipe, byte wood) {
|
public int calcQuality(BRecipe recipe, byte wood, boolean distilled) {
|
||||||
// calculate quality from all of the factors
|
// calculate quality from all of the factors
|
||||||
float quality = (
|
float quality = (
|
||||||
|
|
||||||
ingredients.getIngredientQuality(recipe) +
|
ingredients.getIngredientQuality(recipe) +
|
||||||
ingredients.getCookingQuality(recipe) +
|
ingredients.getCookingQuality(recipe, distilled) +
|
||||||
ingredients.getWoodQuality(recipe, wood) +
|
ingredients.getWoodQuality(recipe, wood) +
|
||||||
ingredients.getAgeQuality(recipe, ageTime));
|
ingredients.getAgeQuality(recipe, ageTime));
|
||||||
|
|
||||||
@@ -138,6 +141,17 @@ public class Brew {
|
|||||||
return quality;
|
return quality;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean canDistill() {
|
||||||
|
if (distillRuns >= 6) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (currentRecipe != null) {
|
||||||
|
return currentRecipe.needsDistilling();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// return special effect
|
// return special effect
|
||||||
public String getEffect() {
|
public String getEffect() {
|
||||||
if (currentRecipe != null) {
|
if (currentRecipe != null) {
|
||||||
@@ -156,10 +170,10 @@ public class Brew {
|
|||||||
// Distilling section ---------------
|
// Distilling section ---------------
|
||||||
|
|
||||||
// distill all custom potions in the brewer
|
// distill all custom potions in the brewer
|
||||||
public static void distillAll(BrewerInventory inv, Integer[] contents) {
|
public static void distillAll(BrewerInventory inv, Boolean[] contents) {
|
||||||
int slot = 0;
|
int slot = 0;
|
||||||
while (slot < 3) {
|
while (slot < 3) {
|
||||||
if (contents[slot] == 1) {
|
if (contents[slot]) {
|
||||||
distillSlot(inv, slot);
|
distillSlot(inv, slot);
|
||||||
}
|
}
|
||||||
slot++;
|
slot++;
|
||||||
@@ -174,8 +188,7 @@ public class Brew {
|
|||||||
BRecipe recipe = brew.ingredients.getdistillRecipe();
|
BRecipe recipe = brew.ingredients.getdistillRecipe();
|
||||||
|
|
||||||
if (recipe != null) {
|
if (recipe != null) {
|
||||||
brew.quality = brew.calcQuality(recipe, (byte) 0);
|
brew.quality = brew.calcQuality(recipe, (byte) 0, true);
|
||||||
P.p.log("destilled " + recipe.getName(5) + " has Quality: " + brew.quality);
|
|
||||||
brew.distillRuns += 1;
|
brew.distillRuns += 1;
|
||||||
// distillRuns will have an effect on the amount of alcohol, not the quality
|
// distillRuns will have an effect on the amount of alcohol, not the quality
|
||||||
if (brew.distillRuns > 1) {
|
if (brew.distillRuns > 1) {
|
||||||
@@ -184,6 +197,7 @@ public class Brew {
|
|||||||
potionMeta.setLore(lore);
|
potionMeta.setLore(lore);
|
||||||
}
|
}
|
||||||
brew.currentRecipe = recipe;
|
brew.currentRecipe = recipe;
|
||||||
|
P.p.log("destilled " + recipe.getName(5) + " has Quality: " + brew.quality + ", alc: " + brew.calcAlcohol());
|
||||||
|
|
||||||
potionMeta.setDisplayName(recipe.getName(brew.quality));
|
potionMeta.setDisplayName(recipe.getName(brew.quality));
|
||||||
|
|
||||||
@@ -195,7 +209,7 @@ public class Brew {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
potionMeta.setDisplayName("Undefinierbares Destillat");
|
potionMeta.setDisplayName("Undefinierbares Destillat");
|
||||||
slotItem.setDurability(PotionColor.GREY.getColorId(true));
|
slotItem.setDurability(PotionColor.GREY.getColorId(brew.distillRuns <= 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
slotItem.setItemMeta(potionMeta);
|
slotItem.setItemMeta(potionMeta);
|
||||||
@@ -210,11 +224,11 @@ public class Brew {
|
|||||||
brew.ageTime += time;
|
brew.ageTime += time;
|
||||||
// if younger than half a day, it shouldnt get aged form
|
// if younger than half a day, it shouldnt get aged form
|
||||||
if (brew.ageTime > 0.5) {
|
if (brew.ageTime > 0.5) {
|
||||||
BRecipe recipe = brew.ingredients.getAgeRecipe(wood, brew.ageTime);
|
BRecipe recipe = brew.ingredients.getAgeRecipe(wood, brew.ageTime, brew.distillRuns > 0);
|
||||||
if (recipe != null) {
|
if (recipe != null) {
|
||||||
if (!recipe.needsDistilling() || brew.distillRuns > 0) {
|
//if (!recipe.needsDistilling() || brew.distillRuns > 0) {
|
||||||
|
|
||||||
brew.quality = brew.calcQuality(recipe, wood);
|
brew.quality = brew.calcQuality(recipe, wood, brew.distillRuns > 0);
|
||||||
brew.currentRecipe = recipe;
|
brew.currentRecipe = recipe;
|
||||||
P.p.log("Final " + recipe.getName(5) + " has Quality: " + brew.quality);
|
P.p.log("Final " + recipe.getName(5) + " has Quality: " + brew.quality);
|
||||||
|
|
||||||
@@ -249,7 +263,7 @@ public class Brew {
|
|||||||
potionMeta.setDisplayName(recipe.getName(brew.quality));
|
potionMeta.setDisplayName(recipe.getName(brew.quality));
|
||||||
item.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(false));
|
item.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(false));
|
||||||
item.setItemMeta(potionMeta);
|
item.setItemMeta(potionMeta);
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -335,7 +335,8 @@ public class P extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
p.log("Update");
|
long time = System.nanoTime();
|
||||||
|
|
||||||
for (BCauldron cauldron : BCauldron.bcauldrons) {
|
for (BCauldron cauldron : BCauldron.bcauldrons) {
|
||||||
cauldron.onUpdate();// runs every min to update cooking time
|
cauldron.onUpdate();// runs every min to update cooking time
|
||||||
}
|
}
|
||||||
@@ -344,8 +345,16 @@ public class P extends JavaPlugin {
|
|||||||
|
|
||||||
if (lastSave >= autosave) {
|
if (lastSave >= autosave) {
|
||||||
saveData();// save all data
|
saveData();// save all data
|
||||||
|
|
||||||
|
time = System.nanoTime() - time;
|
||||||
|
float ftime = (float) (time / 1000000.0);
|
||||||
|
p.log("Update and saving (" + ftime + "ms)");
|
||||||
} else {
|
} else {
|
||||||
lastSave++;
|
lastSave++;
|
||||||
|
|
||||||
|
time = System.nanoTime() - time;
|
||||||
|
float ftime = (float) (time / 1000000.0);
|
||||||
|
p.log("Update (" + ftime + "ms)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,17 +18,21 @@ public class InventoryListener implements Listener {
|
|||||||
BrewerInventory inv = event.getContents();
|
BrewerInventory inv = event.getContents();
|
||||||
ItemStack item;
|
ItemStack item;
|
||||||
boolean custom = false;
|
boolean custom = false;
|
||||||
Integer[] contents = new Integer[3];
|
Boolean[] contents = new Boolean[3];
|
||||||
while (slot < 3) {
|
while (slot < 3) {
|
||||||
item = inv.getItem(slot);
|
item = inv.getItem(slot);
|
||||||
contents[slot] = 0;
|
contents[slot] = false;
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
if (item.getType() == Material.POTION) {
|
if (item.getType() == Material.POTION) {
|
||||||
if (item.hasItemMeta()) {
|
if (item.hasItemMeta()) {
|
||||||
if (Brew.potions.containsKey(Brew.getUID(item))) {
|
int uid = Brew.getUID(item);
|
||||||
|
if (Brew.potions.containsKey(uid)) {
|
||||||
// has custom potion in "slot"
|
// has custom potion in "slot"
|
||||||
contents[slot] = 1;
|
if (Brew.get(uid).canDistill()) {
|
||||||
custom = true;
|
// is further distillable
|
||||||
|
contents[slot] = true;
|
||||||
|
custom = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user