v0.7.0: corrected issues with simple recipes & multiple of the same item
This commit is contained in:
parent
2c1c830551
commit
9b42908273
|
@ -51,7 +51,7 @@ public abstract class Recipe {
|
||||||
public static abstract class SimpleRecipe extends Recipe {
|
public static abstract class SimpleRecipe extends Recipe {
|
||||||
|
|
||||||
//*** These elements must be filled in by subclasses
|
//*** These elements must be filled in by subclasses
|
||||||
protected Class<?extends Item>[] inputs;
|
protected Class<?extends Item>[] inputs; //each class should be unique
|
||||||
protected int[] inQuantity;
|
protected int[] inQuantity;
|
||||||
|
|
||||||
protected int cost;
|
protected int cost;
|
||||||
|
@ -62,20 +62,24 @@ public abstract class Recipe {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean testIngredients(ArrayList<Item> ingredients) {
|
public final boolean testIngredients(ArrayList<Item> ingredients) {
|
||||||
boolean found;
|
|
||||||
for(int i = 0; i < inputs.length; i++){
|
int[] needed = inQuantity.clone();
|
||||||
found = false;
|
|
||||||
for (Item ingredient : ingredients){
|
for (Item ingredient : ingredients){
|
||||||
if (ingredient.getClass() == inputs[i]
|
for (int i = 0; i < inputs.length; i++){
|
||||||
&& ingredient.quantity() >= inQuantity[i]){
|
if (ingredient.getClass() == inputs[i]){
|
||||||
found = true;
|
needed[i] -= ingredient.quantity();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found){
|
}
|
||||||
|
|
||||||
|
for (int i : needed){
|
||||||
|
if (i > 0){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,11 +91,18 @@ public abstract class Recipe {
|
||||||
public final Item brew(ArrayList<Item> ingredients) {
|
public final Item brew(ArrayList<Item> ingredients) {
|
||||||
if (!testIngredients(ingredients)) return null;
|
if (!testIngredients(ingredients)) return null;
|
||||||
|
|
||||||
for(int i = 0; i < inputs.length; i++){
|
int[] needed = inQuantity.clone();
|
||||||
for (Item ingredient : ingredients){
|
|
||||||
if (ingredient.getClass() == inputs[i]){
|
for (Item ingredient : ingredients){
|
||||||
ingredient.quantity( ingredient.quantity()-inQuantity[i]);
|
for (int i = 0; i < inputs.length; i++) {
|
||||||
break;
|
if (ingredient.getClass() == inputs[i] && needed[i] > 0) {
|
||||||
|
if (needed[i] <= ingredient.quantity()) {
|
||||||
|
ingredient.quantity(ingredient.quantity() - needed[i]);
|
||||||
|
needed[i] = 0;
|
||||||
|
} else {
|
||||||
|
needed[i] -= ingredient.quantity();
|
||||||
|
ingredient.quantity(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user