mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2025-01-06 18:47:44 +01:00
Save Alc content on the Brew
This commit is contained in:
parent
4c77944eb8
commit
81ea014e45
@ -116,8 +116,9 @@ public class BIngredients {
|
||||
if (cookRecipe != null) {
|
||||
// Potion is best with cooking only
|
||||
int quality = (int) Math.round((getIngredientQuality(cookRecipe) + getCookingQuality(cookRecipe, false)) / 2.0);
|
||||
P.p.debugLog("cooked potion has Quality: " + quality);
|
||||
brew = new Brew(quality, cookRecipe, this);
|
||||
int alc = (int) Math.round(cookRecipe.getAlcohol() * ((float) quality / 10.0f));
|
||||
P.p.debugLog("cooked potion has Quality: " + quality + ", Alc: " + alc);
|
||||
brew = new Brew(quality, alc, cookRecipe, this);
|
||||
BrewLore lore = new BrewLore(brew, potionMeta);
|
||||
lore.updateQualityStars(false);
|
||||
lore.updateCustomLore();
|
||||
|
@ -36,6 +36,7 @@ public class Brew {
|
||||
|
||||
private BIngredients ingredients;
|
||||
private int quality;
|
||||
private int alc;
|
||||
private byte distillRuns;
|
||||
private float ageTime;
|
||||
private float wood;
|
||||
@ -52,17 +53,19 @@ public class Brew {
|
||||
}
|
||||
|
||||
// quality already set
|
||||
public Brew(int quality, BRecipe recipe, BIngredients ingredients) {
|
||||
public Brew(int quality, int alc, BRecipe recipe, BIngredients ingredients) {
|
||||
this.ingredients = ingredients;
|
||||
this.quality = quality;
|
||||
this.alc = alc;
|
||||
this.currentRecipe = recipe;
|
||||
touch();
|
||||
}
|
||||
|
||||
// loading with all values set
|
||||
public Brew(BIngredients ingredients, int quality, byte distillRuns, float ageTime, float wood, String recipe, boolean unlabeled, boolean immutable, int lastUpdate) {
|
||||
public Brew(BIngredients ingredients, int quality, int alc, byte distillRuns, float ageTime, float wood, String recipe, boolean unlabeled, boolean immutable, int lastUpdate) {
|
||||
this.ingredients = ingredients;
|
||||
this.quality = quality;
|
||||
this.alc = alc;
|
||||
this.distillRuns = distillRuns;
|
||||
this.ageTime = ageTime;
|
||||
this.wood = wood;
|
||||
@ -97,6 +100,7 @@ public class Brew {
|
||||
if (!item.hasItemMeta()) return null;
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
if (!P.useNBT && !meta.hasLore()) return null;
|
||||
|
||||
Brew brew = load(meta);
|
||||
@ -207,9 +211,9 @@ public class Brew {
|
||||
if (quality > 0) {
|
||||
currentRecipe = ingredients.getBestRecipe(wood, ageTime, distillRuns > 0);
|
||||
if (currentRecipe != null) {
|
||||
if (!immutable) {
|
||||
/*if (!immutable) {
|
||||
this.quality = calcQuality();
|
||||
}
|
||||
}*/
|
||||
P.p.log("A Brew was made from Recipe: '" + name + "' which could not be found. '" + currentRecipe.getRecipeName() + "' used instead!");
|
||||
return true;
|
||||
} else {
|
||||
@ -244,6 +248,7 @@ public class Brew {
|
||||
if (brew == null) return false;
|
||||
if (equals(brew)) return true;
|
||||
return quality == brew.quality &&
|
||||
alc == brew.alc &&
|
||||
distillRuns == brew.distillRuns &&
|
||||
Float.compare(brew.ageTime, ageTime) == 0 &&
|
||||
Float.compare(brew.wood, wood) == 0 &&
|
||||
@ -258,7 +263,7 @@ public class Brew {
|
||||
@Override
|
||||
public Brew clone() throws CloneNotSupportedException {
|
||||
super.clone();
|
||||
Brew brew = new Brew(quality, currentRecipe, ingredients);
|
||||
Brew brew = new Brew(quality, alc, currentRecipe, ingredients);
|
||||
brew.distillRuns = distillRuns;
|
||||
brew.ageTime = ageTime;
|
||||
brew.unlabeled = unlabeled;
|
||||
@ -272,6 +277,7 @@ public class Brew {
|
||||
return "Brew{" +
|
||||
ingredients + " ingredients" +
|
||||
", quality=" + quality +
|
||||
", alc=" + alc +
|
||||
", distillRuns=" + distillRuns +
|
||||
", ageTime=" + ageTime +
|
||||
", wood=" + wood +
|
||||
@ -317,13 +323,13 @@ public class Brew {
|
||||
return 0;
|
||||
}
|
||||
// bad quality can decrease alc by up to 40%
|
||||
alc *= 1 - ((float) (10 - quality) * 0.04);
|
||||
alc *= 1 - ((float) (10 - quality) * 0.04f);
|
||||
// distillable Potions should have half alc after one and full alc after all needed distills
|
||||
alc /= 2;
|
||||
alc *= 1.0F + ((float) distillRuns / currentRecipe.getDistillRuns());
|
||||
} else {
|
||||
// quality decides 10% - 100%
|
||||
alc *= ((float) quality / 10.0);
|
||||
alc *= ((float) quality / 10.0f);
|
||||
}
|
||||
if (alc > 0) {
|
||||
return alc;
|
||||
@ -391,6 +397,14 @@ public class Brew {
|
||||
lastUpdate = (int) ((double) (System.currentTimeMillis() - installTime) / 3600000D);
|
||||
}
|
||||
|
||||
public int getOrCalcAlc() {
|
||||
return alc > 0 ? alc : (alc = calcAlcohol());
|
||||
}
|
||||
|
||||
public void setAlc(int alc) {
|
||||
this.alc = alc;
|
||||
}
|
||||
|
||||
public byte getDistillRuns() {
|
||||
return distillRuns;
|
||||
}
|
||||
@ -507,6 +521,7 @@ public class Brew {
|
||||
potionMeta.setDisplayName(P.p.color("&f" + P.p.languageReader.get("Brew_DistillUndefined")));
|
||||
PotionColor.GREY.colorBrew(potionMeta, slotItem, canDistill());
|
||||
}
|
||||
alc = calcAlcohol();
|
||||
|
||||
// Distill Lore
|
||||
if (currentRecipe != null && BConfig.colorInBrewer != BrewLore.hasColorLore(potionMeta)) {
|
||||
@ -580,6 +595,7 @@ public class Brew {
|
||||
PotionColor.GREY.colorBrew(potionMeta, item, canDistill());
|
||||
}
|
||||
}
|
||||
alc = calcAlcohol();
|
||||
|
||||
// Lore
|
||||
if (currentRecipe != null && BConfig.colorInBarrels != BrewLore.hasColorLore(potionMeta)) {
|
||||
@ -756,6 +772,9 @@ public class Brew {
|
||||
private void loadFromStream(DataInputStream in, byte dataVersion) throws IOException {
|
||||
quality = in.readByte();
|
||||
int bools = in.readUnsignedByte();
|
||||
if ((bools & 64) != 0) {
|
||||
alc = in.readShort();
|
||||
}
|
||||
if ((bools & 1) != 0) {
|
||||
distillRuns = in.readByte();
|
||||
}
|
||||
@ -817,6 +836,7 @@ public class Brew {
|
||||
if (quality > 10) {
|
||||
quality = 10;
|
||||
}
|
||||
alc = Math.min(alc, Short.MAX_VALUE);
|
||||
out.writeByte((byte) quality);
|
||||
int bools = 0;
|
||||
bools |= ((distillRuns != 0) ? 1 : 0);
|
||||
@ -824,9 +844,12 @@ public class Brew {
|
||||
bools |= (wood != -1 ? 4 : 0);
|
||||
bools |= (currentRecipe != null ? 8 : 0);
|
||||
bools |= (unlabeled ? 16 : 0);
|
||||
//bools |= (persistent ? 32 : 0);
|
||||
bools |= (immutable ? 32 : 0);
|
||||
bools |= (alc > 0 ? 64 : 0);
|
||||
out.writeByte(bools);
|
||||
if (alc > 0) {
|
||||
out.writeShort(alc);
|
||||
}
|
||||
if (distillRuns != 0) {
|
||||
out.writeByte(distillRuns);
|
||||
}
|
||||
@ -877,8 +900,8 @@ public class Brew {
|
||||
}
|
||||
|
||||
// Load potion data from data file for backwards compatibility
|
||||
public static void loadLegacy(BIngredients ingredients, int uid, int quality, byte distillRuns, float ageTime, float wood, String recipe, boolean unlabeled, boolean persistent, boolean stat, int lastUpdate) {
|
||||
Brew brew = new Brew(ingredients, quality, distillRuns, ageTime, wood, recipe, unlabeled, stat, lastUpdate);
|
||||
public static void loadLegacy(BIngredients ingredients, int uid, int quality, int alc, byte distillRuns, float ageTime, float wood, String recipe, boolean unlabeled, boolean persistent, boolean stat, int lastUpdate) {
|
||||
Brew brew = new Brew(ingredients, quality, alc, distillRuns, ageTime, wood, recipe, unlabeled, stat, lastUpdate);
|
||||
brew.persistent = persistent;
|
||||
legacyPotions.put(uid, brew);
|
||||
}
|
||||
@ -920,6 +943,9 @@ public class Brew {
|
||||
if (brew.quality != 0) {
|
||||
idConfig.set("quality", brew.quality);
|
||||
}
|
||||
if (brew.alc > 0) {
|
||||
idConfig.set("alc", brew.alc);
|
||||
}
|
||||
if (brew.distillRuns != 0) {
|
||||
idConfig.set("distillRuns", brew.distillRuns);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public class BrewDrinkEvent extends BrewEvent implements Cancellable {
|
||||
super(brew, meta);
|
||||
this.player = player;
|
||||
this.bPlayer = bPlayer;
|
||||
alc = brew.calcAlcohol();
|
||||
alc = brew.getOrCalcAlc();
|
||||
quality = brew.getQuality();
|
||||
}
|
||||
|
||||
|
@ -85,6 +85,7 @@ public class BData {
|
||||
for (String uid : section.getKeys(false)) {
|
||||
BIngredients ingredients = getIngredients(ingMap, section.getString(uid + ".ingId"));
|
||||
int quality = section.getInt(uid + ".quality", 0);
|
||||
int alc = section.getInt(uid + ".alc", 0);
|
||||
byte distillRuns = (byte) section.getInt(uid + ".distillRuns", 0);
|
||||
float ageTime = (float) section.getDouble(uid + ".ageTime", 0.0);
|
||||
float wood = (float) section.getDouble(uid + ".wood", -1.0);
|
||||
@ -94,7 +95,7 @@ public class BData {
|
||||
boolean stat = section.getBoolean(uid + ".stat", false);
|
||||
int lastUpdate = section.getInt("lastUpdate", 0);
|
||||
|
||||
Brew.loadLegacy(ingredients, P.p.parseInt(uid), quality, distillRuns, ageTime, wood, recipe, unlabeled, persistent, stat, lastUpdate);
|
||||
Brew.loadLegacy(ingredients, P.p.parseInt(uid), quality, alc, distillRuns, ageTime, wood, recipe, unlabeled, persistent, stat, lastUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,7 +240,7 @@ public class BrewLore {
|
||||
|
||||
public void updateAlc(boolean inDistiller) {
|
||||
if (!brew.isUnlabeled() && (inDistiller || BConfig.alwaysShowAlc) && (!brew.hasRecipe() || brew.getCurrentRecipe().getAlcohol() > 0)) {
|
||||
int alc = brew.calcAlcohol();
|
||||
int alc = brew.getOrCalcAlc();
|
||||
addOrReplaceLore(Type.ALC, "§8", P.p.languageReader.get("Brew_Alc", alc + ""));
|
||||
} else {
|
||||
removeLore(Type.ALC);
|
||||
|
@ -377,7 +377,7 @@ public class BRecipe {
|
||||
|
||||
BIngredients bIngredients = new BIngredients(list, cookingTime);
|
||||
|
||||
return new Brew(bIngredients, quality, distillruns, getAge(), wood, getRecipeName(), false, true, 0);
|
||||
return new Brew(bIngredients, quality, 0, distillruns, getAge(), wood, getRecipeName(), false, true, 0);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user