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