Slightly larger En/Decoder buffers, isSimilar for Brew

This commit is contained in:
Sn0wStorm 2016-06-30 14:34:16 +02:00
parent 2121bf5c8a
commit 562f96e4b1
6 changed files with 59 additions and 17 deletions

View File

@ -327,6 +327,16 @@ public class BIngredients {
return Math.max(quality, 0); return Math.max(quality, 0);
} }
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof BIngredients)) return false;
BIngredients other = ((BIngredients) obj);
return cookedTime == other.cookedTime &&
ingredients.equals(other.ingredients) &&
materials.equals(other.materials);
}
// Creates a copy ingredients // Creates a copy ingredients
@Override @Override
public BIngredients clone() { public BIngredients clone() {

View File

@ -6,6 +6,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
public class BRecipe { public class BRecipe {
@ -251,18 +252,7 @@ public class BRecipe {
ItemStack potion = new ItemStack(Material.POTION); ItemStack potion = new ItemStack(Material.POTION);
PotionMeta potionMeta = (PotionMeta) potion.getItemMeta(); PotionMeta potionMeta = (PotionMeta) potion.getItemMeta();
ArrayList<ItemStack> list = new ArrayList<>(ingredients.size()); Brew brew = createBrew(quality);
for (ItemStack item : ingredients) {
if (item.getDurability() == -1) {
list.add(new ItemStack(item.getType(), item.getAmount()));
} else {
list.add(item.clone());
}
}
BIngredients bIngredients = new BIngredients(list, cookingTime);
Brew brew = new Brew(bIngredients, quality, distillruns, getAge(), wood, getName(5), false, true);
Brew.PotionColor.fromString(getColor()).colorBrew(potionMeta, potion, false); Brew.PotionColor.fromString(getColor()).colorBrew(potionMeta, potion, false);
potionMeta.setDisplayName(P.p.color("&f" + getName(quality))); potionMeta.setDisplayName(P.p.color("&f" + getName(quality)));
@ -283,6 +273,21 @@ public class BRecipe {
return potion; return potion;
} }
public Brew createBrew(int quality) {
ArrayList<ItemStack> list = new ArrayList<>(ingredients.size());
for (ItemStack item : ingredients) {
if (item.getDurability() == -1) {
list.add(new ItemStack(item.getType(), item.getAmount()));
} else {
list.add(item.clone());
}
}
BIngredients bIngredients = new BIngredients(list, cookingTime);
return new Brew(bIngredients, quality, distillruns, getAge(), wood, getName(5), false, true);
}
// Getter // Getter
@ -365,4 +370,13 @@ public class BRecipe {
public String toString() { public String toString() {
return "BRecipe{" + getName(5) + '}'; return "BRecipe{" + getName(5) + '}';
} }
public static BRecipe get(String name) {
for (BRecipe recipe : BIngredients.recipes) {
if (recipe.getName(5).equalsIgnoreCase(name)) {
return recipe;
}
}
return null;
}
} }

View File

@ -222,6 +222,20 @@ public class Brew {
return copy; return copy;
}*/ }*/
public boolean isSimilar(Brew brew) {
if (brew == null) return false;
if (equals(brew)) return true;
return quality == brew.quality &&
distillRuns == brew.distillRuns &&
Float.compare(brew.ageTime, ageTime) == 0 &&
Float.compare(brew.wood, wood) == 0 &&
unlabeled == brew.unlabeled &&
persistent == brew.persistent &&
immutable == brew.immutable &&
ingredients.equals(brew.ingredients) &&
currentRecipe != null ? currentRecipe.equals(brew.currentRecipe) : brew.currentRecipe == null;
}
// Clones this instance // Clones this instance
@Override @Override
public Brew clone() throws CloneNotSupportedException { public Brew clone() throws CloneNotSupportedException {

View File

@ -298,6 +298,8 @@ public class InventoryListener implements Listener {
} }
P.p.log(brew.toString()); P.p.log(brew.toString());
P.p.log(potion.getLore().get(0).replaceAll("§", "")); P.p.log(potion.getLore().get(0).replaceAll("§", ""));
P.p.log("similar to beispiel? " + BRecipe.get("Beispiel").createBrew(10).isSimilar(brew));
//brew.touch(); //brew.touch();
/*try { /*try {

View File

@ -7,8 +7,8 @@ import java.io.InputStream;
public class Base91DecoderStream extends FilterInputStream { public class Base91DecoderStream extends FilterInputStream {
private final basE91 decoder = new basE91(); private final basE91 decoder = new basE91();
private byte[] decbuf = new byte[18]; private byte[] decbuf = new byte[32];
private byte[] buf = new byte[18]; private byte[] buf = new byte[32];
private int reader = 0; private int reader = 0;
private int count = 0; private int count = 0;
private byte[] markBuf = null; private byte[] markBuf = null;
@ -62,6 +62,7 @@ public class Base91DecoderStream extends FilterInputStream {
int out = 0; int out = 0;
int writeSize; int writeSize;
while (count > 0) { while (count > 0) {
// Not enough data in buffer, write all out, decode and repeat
writeSize = Math.min(len, count - reader); writeSize = Math.min(len, count - reader);
System.arraycopy(buf, reader, b, off + out, writeSize); System.arraycopy(buf, reader, b, off + out, writeSize);
out += writeSize; out += writeSize;
@ -99,7 +100,8 @@ public class Base91DecoderStream extends FilterInputStream {
@Override @Override
public int available() throws IOException { public int available() throws IOException {
return (int) (in.available() * 0.813F); // Ratio encoded to decoded with random data if (count == -1) return 0;
return (int) (in.available() * 0.813F) + count - reader; // Ratio encoded to decoded with random data
} }
@Override @Override

View File

@ -8,8 +8,8 @@ import java.io.OutputStream;
public class Base91EncoderStream extends FilterOutputStream { public class Base91EncoderStream extends FilterOutputStream {
private final basE91 encoder = new basE91(); private final basE91 encoder = new basE91();
private byte[] buf = new byte[16]; private byte[] buf = new byte[32];
private byte[] encBuf = new byte[24]; private byte[] encBuf = new byte[48];
private int writer = 0; private int writer = 0;
private int encoded = 0; private int encoded = 0;