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
// correct one...
public BRecipe getBestRecipe(byte wood, float time, boolean distilled) {
public BRecipe getBestRecipe(float wood, float time, boolean distilled) {
float quality = 0;
int ingredientQuality = 0;
int cookingQuality = 0;
@ -141,7 +141,7 @@ public class BIngredients {
cookingQuality = getCookingQuality(recipe, distilled);
if (ingredientQuality > -1 && cookingQuality > -1) {
if (recipe.needsToAge()) {
if (recipe.needsToAge() || time > 0.5) {
// needs riping in barrel
ageQuality = getAgeQuality(recipe, time);
woodQuality = getWoodQuality(recipe, wood);
@ -172,7 +172,7 @@ public class BIngredients {
// returns recipe that is cooking only and matches the ingredients and
// cooking time
public BRecipe getCookRecipe() {
BRecipe bestRecipe = getBestRecipe((byte) 0, 0, false);
BRecipe bestRecipe = getBestRecipe(0, 0, false);
// Check if best recipe is cooking only
if (bestRecipe != null) {
@ -185,8 +185,8 @@ public class BIngredients {
// returns the currently best matching recipe for distilling for the
// ingredients and cooking time
public BRecipe getdistillRecipe() {
BRecipe bestRecipe = getBestRecipe((byte) 0, 0, true);
public BRecipe getdistillRecipe(float wood, float time) {
BRecipe bestRecipe = getBestRecipe(wood, time, true);
// Check if best recipe needs to be destilled
if (bestRecipe != null) {
@ -199,7 +199,7 @@ public class BIngredients {
// returns currently best matching recipe for ingredients, cooking- and
// 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);
if (bestRecipe != null) {
@ -273,12 +273,13 @@ public class BIngredients {
}
// returns the quality regarding the barrel wood conditioning given Recipe
public int getWoodQuality(BRecipe recipe, byte wood) {
if (recipe.getWood() == 0x8) {
public int getWoodQuality(BRecipe recipe, float wood) {
if (recipe.getWood() == 0) {
// type of wood doesnt matter
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) {
return quality;

View File

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

View File

@ -76,23 +76,25 @@ public class Barrel {
inventory = org.bukkit.Bukkit.createInventory(null, 9, "Fass");
}
} else {
// if nobody has the inventory opened
if (inventory.getViewers().isEmpty()) {
// if inventory contains potions
if (inventory.contains(373)) {
byte wood = getWood();
long loadTime = System.nanoTime();
for (ItemStack item : inventory.getContents()) {
if (item != null) {
Brew brew = Brew.get(item);
if (brew != null) {
brew.age(item, time, wood);
if (time > 0) {
// if nobody has the inventory opened
if (inventory.getViewers().isEmpty()) {
// if inventory contains potions
if (inventory.contains(373)) {
byte wood = getWood();
long loadTime = System.nanoTime();
for (ItemStack item : inventory.getContents()) {
if (item != null) {
Brew brew = Brew.get(item);
if (brew != null) {
brew.age(item, time, wood);
}
}
}
loadTime = System.nanoTime() - loadTime;
float ftime = (float) (loadTime / 1000000.0);
P.p.log("opening Barrel with potions (" + ftime + "ms)");
}
loadTime = System.nanoTime() - loadTime;
float ftime = (float) (loadTime / 1000000.0);
P.p.log("opening Barrel with potions (" + ftime + "ms)");
}
}
}
@ -282,19 +284,28 @@ public class Barrel {
wood = this.spigot.getRelative(0, 0, -1);
}
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) {
return 0x0;
return 2;
}
if (wood.getTypeId() == 134) {
return 0x1;
return 4;
}
if (wood.getTypeId() == 135) {
return 0x2;
return 1;
}
if (wood.getTypeId() == 136) {
return 0x3;
return 3;
}
return 0;
}

View File

@ -28,6 +28,7 @@ public class Brew {
private int quality;
private int distillRuns;
private float ageTime;
private float wood;
private BRecipe currentRecipe;
private boolean unlabeled;
@ -45,11 +46,12 @@ public class Brew {
}
// 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.quality = quality;
this.distillRuns = distillRuns;
this.ageTime = ageTime;
this.wood = wood;
this.currentRecipe = BIngredients.getRecipeByName(recipe);
this.unlabeled = unlabeled;
potions.put(uid, this);
@ -182,16 +184,15 @@ public class Brew {
}
// calculating quality
public int calcQuality(BRecipe recipe, byte wood, boolean distilled) {
public int calcQuality() {
// calculate quality from all of the factors
float quality = (
ingredients.getIngredientQuality(recipe) +
ingredients.getCookingQuality(recipe, distilled) +
ingredients.getWoodQuality(recipe, wood) +
ingredients.getAgeQuality(recipe, ageTime));
quality /= 4;
float quality = ingredients.getIngredientQuality(currentRecipe) + ingredients.getCookingQuality(currentRecipe, distillRuns > 0);
if (currentRecipe.needsToAge() || ageTime > 0.5) {
quality += ingredients.getWoodQuality(currentRecipe, wood) + ingredients.getAgeQuality(currentRecipe, ageTime);
quality /= 4;
} else {
quality /= 2;
}
return (int) Math.round(quality);
}
@ -250,11 +251,11 @@ public class Brew {
// distill custom potion in given slot
public void distillSlot(ItemStack slotItem, PotionMeta potionMeta) {
distillRuns += 1;
BRecipe recipe = ingredients.getdistillRecipe();
BRecipe recipe = ingredients.getdistillRecipe(wood, ageTime);
if (recipe != null) {
// distillRuns will have an effect on the amount of alcohol, not the quality
quality = calcQuality(recipe, (byte) 0, true);
currentRecipe = recipe;
quality = calcQuality();
P.p.log("destilled " + recipe.getName(5) + " has Quality: " + quality + ", alc: " + calcAlcohol());
addOrReplaceEffects(potionMeta, getEffects());
@ -283,16 +284,23 @@ public class Brew {
// 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();
ageTime += time;
// if younger than half a day, it shouldnt get aged form
if (ageTime > 0.5) {
if (wood == 0) {
wood = woodType;
} else {
if (wood != woodType) {
woodShift(time, woodType);
}
}
BRecipe recipe = ingredients.getAgeRecipe(wood, ageTime, distillRuns > 0);
if (recipe != null) {
currentRecipe = recipe;
quality = calcQuality(recipe, wood, distillRuns > 0);
quality = calcQuality();
P.p.log("Final " + recipe.getName(5) + " has Quality: " + quality + ", alc: " + calcAlcohol());
addOrReplaceEffects(potionMeta, getEffects());
@ -318,9 +326,36 @@ public class Brew {
}
updateAgeLore(prefix, potionMeta);
}
if (ageTime > 0.5) {
if (colorInBarrels && !unlabeled && currentRecipe != null) {
updateWoodLore(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 -----------
// Converts to/from qualitycolored Lore
@ -371,6 +406,13 @@ public class Brew {
}
updateAgeLore(prefix, meta);
}
// WoodType
if (toQuality && !unlabeled) {
if (ageTime > 0.5) {
updateWoodLore(meta);
}
}
}
// sets the DistillLore. Prefix is the color to be used
@ -397,6 +439,23 @@ public class Brew {
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
public static void addOrReplaceLore(PotionMeta meta, String prefix, String lore) {
if (meta.hasLore()) {
@ -482,6 +541,9 @@ public class Brew {
if (brew.ageTime != 0) {
idConfig.set("ageTime", brew.ageTime);
}
if (brew.wood != -1) {
idConfig.set("wood", brew.wood);
}
if (brew.currentRecipe != null) {
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 distillRuns = section.getInt(uid + ".distillRuns", 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);
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);
}
}