Reworked Barrel Wood Type

This commit is contained in:
Sn0wStorm 2013-09-05 17:09:20 +02:00
parent a990e91496
commit 8a5f19899c
5 changed files with 124 additions and 68 deletions

View File

@ -129,7 +129,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, boolean distilled) { public BRecipe getBestRecipe(float wood, float time, boolean distilled) {
float quality = 0; float quality = 0;
int ingredientQuality = 0; int ingredientQuality = 0;
int cookingQuality = 0; int cookingQuality = 0;
@ -141,7 +141,7 @@ public class BIngredients {
cookingQuality = getCookingQuality(recipe, distilled); cookingQuality = getCookingQuality(recipe, distilled);
if (ingredientQuality > -1 && cookingQuality > -1) { if (ingredientQuality > -1 && cookingQuality > -1) {
if (recipe.needsToAge()) { if (recipe.needsToAge() || time > 0.5) {
// needs riping in barrel // needs riping in barrel
ageQuality = getAgeQuality(recipe, time); ageQuality = getAgeQuality(recipe, time);
woodQuality = getWoodQuality(recipe, wood); woodQuality = getWoodQuality(recipe, wood);
@ -172,7 +172,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, false); BRecipe bestRecipe = getBestRecipe(0, 0, false);
// Check if best recipe is cooking only // Check if best recipe is cooking only
if (bestRecipe != null) { if (bestRecipe != null) {
@ -185,8 +185,8 @@ 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(float wood, float time) {
BRecipe bestRecipe = getBestRecipe((byte) 0, 0, true); BRecipe bestRecipe = getBestRecipe(wood, time, true);
// Check if best recipe needs to be destilled // Check if best recipe needs to be destilled
if (bestRecipe != null) { if (bestRecipe != null) {
@ -199,7 +199,7 @@ 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, boolean distilled) { public BRecipe getAgeRecipe(float wood, float time, boolean distilled) {
BRecipe bestRecipe = getBestRecipe(wood, time, distilled); BRecipe bestRecipe = getBestRecipe(wood, time, distilled);
if (bestRecipe != null) { if (bestRecipe != null) {
@ -273,12 +273,13 @@ public class BIngredients {
} }
// returns the quality regarding the barrel wood conditioning given Recipe // returns the quality regarding the barrel wood conditioning given Recipe
public int getWoodQuality(BRecipe recipe, byte wood) { public int getWoodQuality(BRecipe recipe, float wood) {
if (recipe.getWood() == 0x8) { if (recipe.getWood() == 0) {
// type of wood doesnt matter // type of wood doesnt matter
return 10; return 10;
} }
int quality = 10 - (recipe.getWoodDiff(wood) * recipe.getDifficulty()); int quality = 10 - Math.round(recipe.getWoodDiff(wood) * recipe.getDifficulty());
P.p.log("wood: " + wood + " needed: " + recipe.getWood() + " diff: " + recipe.getWoodDiff(wood));
if (quality > 0) { if (quality > 0) {
return quality; return quality;

View File

@ -13,7 +13,7 @@ public class BRecipe {
private Map<Material, Integer> ingredients = new HashMap<Material, Integer>();// material and amount private Map<Material, Integer> ingredients = new HashMap<Material, Integer>();// material and amount
private int cookingTime;// time to cook in cauldron private int cookingTime;// time to cook in cauldron
private int distillruns;// runs through the brewer private int distillruns;// runs through the brewer
private int wood;// type of wood the barrel has to consist of 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 int age;// time in minecraft days for the potions to age in barrels
private String color;// color of the destilled/finished potion 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 difficulty;// difficulty to brew the potion, how exact the instruction has to be followed
@ -36,7 +36,7 @@ public class BRecipe {
} }
this.cookingTime = configSectionRecipes.getInt(recipeId + ".cookingtime"); this.cookingTime = configSectionRecipes.getInt(recipeId + ".cookingtime");
this.distillruns = configSectionRecipes.getInt(recipeId + ".distillruns"); this.distillruns = configSectionRecipes.getInt(recipeId + ".distillruns");
this.wood = configSectionRecipes.getInt(recipeId + ".wood"); this.wood = (byte) configSectionRecipes.getInt(recipeId + ".wood");
this.age = configSectionRecipes.getInt(recipeId + ".age"); this.age = configSectionRecipes.getInt(recipeId + ".age");
this.color = configSectionRecipes.getString(recipeId + ".color"); this.color = configSectionRecipes.getString(recipeId + ".color");
this.difficulty = configSectionRecipes.getInt(recipeId + ".difficulty"); this.difficulty = configSectionRecipes.getInt(recipeId + ".difficulty");
@ -91,18 +91,8 @@ public class BRecipe {
} }
// difference between given and recipe-wanted woodtype // difference between given and recipe-wanted woodtype
public int getWoodDiff(byte wood) { public float getWoodDiff(float wood) {
int woodType = 0; return Math.abs(wood - this.wood);
if (wood == 0x0) {
woodType = 2;
} else if (wood == 0x1) {
woodType = 4;
} else if (wood == 0x2) {
woodType = 1;
} else if (wood == 0x3) {
woodType = 3;
}
return Math.abs(woodType - this.wood);
} }
public boolean isCookingOnly() { public boolean isCookingOnly() {
@ -177,18 +167,9 @@ public class BRecipe {
return color.toUpperCase(); return color.toUpperCase();
} }
// get the woodtype in blockData-byte // get the woodtype
public byte getWood() { public byte getWood() {
if (wood == 1) { return wood;
return 0x2;
} else if (wood == 2) {
return 0x0;
} else if (wood == 3) {
return 0x3;
} else if (wood == 4) {
return 0x1;
}
return 0x8;
} }
public float getAge() { public float getAge() {

View File

@ -76,6 +76,7 @@ public class Barrel {
inventory = org.bukkit.Bukkit.createInventory(null, 9, "Fass"); inventory = org.bukkit.Bukkit.createInventory(null, 9, "Fass");
} }
} else { } else {
if (time > 0) {
// if nobody has the inventory opened // if nobody has the inventory opened
if (inventory.getViewers().isEmpty()) { if (inventory.getViewers().isEmpty()) {
// if inventory contains potions // if inventory contains potions
@ -96,6 +97,7 @@ public class Barrel {
} }
} }
} }
}
// reset barreltime, potions have new age // reset barreltime, potions have new age
time = 0; time = 0;
player.openInventory(inventory); player.openInventory(inventory);
@ -282,19 +284,28 @@ public class Barrel {
wood = this.spigot.getRelative(0, 0, -1); wood = this.spigot.getRelative(0, 0, -1);
} }
if (wood.getTypeId() == 5) { if (wood.getTypeId() == 5) {
return wood.getData(); byte data = wood.getData();
if (data == 0x0) {
return 2;
} else if (data == 0x1) {
return 4;
} else if (data == 0x2) {
return 1;
} else {
return 3;
}
} }
if (wood.getTypeId() == 53) { if (wood.getTypeId() == 53) {
return 0x0; return 2;
} }
if (wood.getTypeId() == 134) { if (wood.getTypeId() == 134) {
return 0x1; return 4;
} }
if (wood.getTypeId() == 135) { if (wood.getTypeId() == 135) {
return 0x2; return 1;
} }
if (wood.getTypeId() == 136) { if (wood.getTypeId() == 136) {
return 0x3; return 3;
} }
return 0; return 0;
} }

View File

@ -28,6 +28,7 @@ public class Brew {
private int quality; private int quality;
private int distillRuns; private int distillRuns;
private float ageTime; private float ageTime;
private float wood;
private BRecipe currentRecipe; private BRecipe currentRecipe;
private boolean unlabeled; private boolean unlabeled;
@ -45,11 +46,12 @@ public class Brew {
} }
// loading from file // loading from file
public Brew(int uid, BIngredients ingredients, int quality, int distillRuns, float ageTime, String recipe, Boolean unlabeled) { public Brew(int uid, BIngredients ingredients, int quality, int distillRuns, float ageTime, float wood, String recipe, Boolean unlabeled) {
this.ingredients = ingredients; this.ingredients = ingredients;
this.quality = quality; this.quality = quality;
this.distillRuns = distillRuns; this.distillRuns = distillRuns;
this.ageTime = ageTime; this.ageTime = ageTime;
this.wood = wood;
this.currentRecipe = BIngredients.getRecipeByName(recipe); this.currentRecipe = BIngredients.getRecipeByName(recipe);
this.unlabeled = unlabeled; this.unlabeled = unlabeled;
potions.put(uid, this); potions.put(uid, this);
@ -182,16 +184,15 @@ public class Brew {
} }
// calculating quality // calculating quality
public int calcQuality(BRecipe recipe, byte wood, boolean distilled) { public int calcQuality() {
// calculate quality from all of the factors // calculate quality from all of the factors
float quality = ( float quality = ingredients.getIngredientQuality(currentRecipe) + ingredients.getCookingQuality(currentRecipe, distillRuns > 0);
if (currentRecipe.needsToAge() || ageTime > 0.5) {
ingredients.getIngredientQuality(recipe) + quality += ingredients.getWoodQuality(currentRecipe, wood) + ingredients.getAgeQuality(currentRecipe, ageTime);
ingredients.getCookingQuality(recipe, distilled) +
ingredients.getWoodQuality(recipe, wood) +
ingredients.getAgeQuality(recipe, ageTime));
quality /= 4; quality /= 4;
} else {
quality /= 2;
}
return (int) Math.round(quality); return (int) Math.round(quality);
} }
@ -250,11 +251,11 @@ public class Brew {
// distill custom potion in given slot // distill custom potion in given slot
public void distillSlot(ItemStack slotItem, PotionMeta potionMeta) { public void distillSlot(ItemStack slotItem, PotionMeta potionMeta) {
distillRuns += 1; distillRuns += 1;
BRecipe recipe = ingredients.getdistillRecipe(); BRecipe recipe = ingredients.getdistillRecipe(wood, ageTime);
if (recipe != null) { if (recipe != null) {
// 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
quality = calcQuality(recipe, (byte) 0, true);
currentRecipe = recipe; currentRecipe = recipe;
quality = calcQuality();
P.p.log("destilled " + recipe.getName(5) + " has Quality: " + quality + ", alc: " + calcAlcohol()); P.p.log("destilled " + recipe.getName(5) + " has Quality: " + quality + ", alc: " + calcAlcohol());
addOrReplaceEffects(potionMeta, getEffects()); addOrReplaceEffects(potionMeta, getEffects());
@ -283,16 +284,23 @@ public class Brew {
// Ageing Section ------------------ // Ageing Section ------------------
public void age(ItemStack item, float time, byte wood) { public void age(ItemStack item, float time, byte woodType) {
PotionMeta potionMeta = (PotionMeta) item.getItemMeta(); PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
ageTime += time; 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 (ageTime > 0.5) { if (ageTime > 0.5) {
if (wood == 0) {
wood = woodType;
} else {
if (wood != woodType) {
woodShift(time, woodType);
}
}
BRecipe recipe = ingredients.getAgeRecipe(wood, ageTime, distillRuns > 0); BRecipe recipe = ingredients.getAgeRecipe(wood, ageTime, distillRuns > 0);
if (recipe != null) { if (recipe != null) {
currentRecipe = recipe; currentRecipe = recipe;
quality = calcQuality(recipe, wood, distillRuns > 0); quality = calcQuality();
P.p.log("Final " + recipe.getName(5) + " has Quality: " + quality + ", alc: " + calcAlcohol()); P.p.log("Final " + recipe.getName(5) + " has Quality: " + quality + ", alc: " + calcAlcohol());
addOrReplaceEffects(potionMeta, getEffects()); addOrReplaceEffects(potionMeta, getEffects());
@ -318,9 +326,36 @@ public class Brew {
} }
updateAgeLore(prefix, potionMeta); updateAgeLore(prefix, potionMeta);
} }
if (ageTime > 0.5) {
if (colorInBarrels && !unlabeled && currentRecipe != null) {
updateWoodLore(potionMeta);
}
}
item.setItemMeta(potionMeta); item.setItemMeta(potionMeta);
} }
// Slowly shift the wood of the Brew to the new Type
public void woodShift(float time, byte to) {
byte factor = 1;
if (ageTime > 5) {
factor = 2;
} else if (ageTime > 10) {
factor = 2;
factor += Math.round(ageTime / 10);
}
if (wood > to) {
wood -= time / factor;
if (wood < to) {
wood = to;
}
} else {
wood += time / factor;
if (wood > to) {
wood = to;
}
}
}
// Lore ----------- // Lore -----------
// Converts to/from qualitycolored Lore // Converts to/from qualitycolored Lore
@ -371,6 +406,13 @@ public class Brew {
} }
updateAgeLore(prefix, meta); updateAgeLore(prefix, meta);
} }
// WoodType
if (toQuality && !unlabeled) {
if (ageTime > 0.5) {
updateWoodLore(meta);
}
}
} }
// sets the DistillLore. Prefix is the color to be used // sets the DistillLore. Prefix is the color to be used
@ -397,6 +439,23 @@ public class Brew {
addOrReplaceLore(meta, prefix, "Fassgereift"); addOrReplaceLore(meta, prefix, "Fassgereift");
} }
// updates/sets the color on WoodLore
public void updateWoodLore(PotionMeta meta) {
if (currentRecipe.getWood() > 0) {
int quality = ingredients.getWoodQuality(currentRecipe, wood);
addOrReplaceLore(meta, getQualityColor(quality), "Holzart");
} else {
if (meta.hasLore()) {
List<String> existingLore = meta.getLore();
int index = indexOfSubstring(existingLore, "Holzart");
if (index > -1) {
existingLore.remove(index);
meta.setLore(existingLore);
}
}
}
}
// Adds or replaces a line of Lore. Searches for Substring lore and replaces it // Adds or replaces a line of Lore. Searches for Substring lore and replaces it
public static void addOrReplaceLore(PotionMeta meta, String prefix, String lore) { public static void addOrReplaceLore(PotionMeta meta, String prefix, String lore) {
if (meta.hasLore()) { if (meta.hasLore()) {
@ -482,6 +541,9 @@ public class Brew {
if (brew.ageTime != 0) { if (brew.ageTime != 0) {
idConfig.set("ageTime", brew.ageTime); idConfig.set("ageTime", brew.ageTime);
} }
if (brew.wood != -1) {
idConfig.set("wood", brew.wood);
}
if (brew.currentRecipe != null) { if (brew.currentRecipe != null) {
idConfig.set("recipe", brew.currentRecipe.getName(5)); idConfig.set("recipe", brew.currentRecipe.getName(5));
} }

View File

@ -220,10 +220,11 @@ public class P extends JavaPlugin {
int quality = section.getInt(uid + ".quality", 0); int quality = section.getInt(uid + ".quality", 0);
int distillRuns = section.getInt(uid + ".distillRuns", 0); int distillRuns = 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);
String recipe = section.getString(uid + ".recipe", null); String recipe = section.getString(uid + ".recipe", null);
Boolean unlabeled = section.getBoolean(uid + ".unlabeled", false); Boolean unlabeled = section.getBoolean(uid + ".unlabeled", false);
new Brew(parseInt(uid), ingredients, quality, distillRuns, ageTime, recipe, unlabeled); new Brew(parseInt(uid), ingredients, quality, distillRuns, ageTime, wood, recipe, unlabeled);
} }
} }