Also try to count recipe ingredients regardless of repairMaterial

when the normal counting and the config value result in 0

Fixes #1484
This commit is contained in:
TfT_02 2013-09-27 13:42:50 +02:00
parent 57dfa00541
commit 1ca53da0e2
2 changed files with 11 additions and 3 deletions

View File

@ -116,21 +116,25 @@ public class Repair {
return getRepairAndSalvageQuantities(inHand, getSalvagedItem(inHand), (byte) -1);
}
public static int getRepairAndSalvageQuantities(ItemStack item) {
return getRepairAndSalvageQuantities(item, null, (byte) -1);
}
public static int getRepairAndSalvageQuantities(ItemStack item, Material repairMaterial, byte repairMetadata) {
int quantity = 0;
MaterialData repairData = new MaterialData(repairMaterial, repairMetadata);
MaterialData repairData = repairMaterial != null ? new MaterialData(repairMaterial, repairMetadata) : null;
Recipe recipe = mcMMO.p.getServer().getRecipesFor(item).get(0);
if (recipe instanceof ShapelessRecipe) {
for (ItemStack ingredient : ((ShapelessRecipe) recipe).getIngredientList()) {
if (ingredient != null && ingredient.getType() == repairMaterial && (repairMetadata == -1 || ingredient.getData() == repairData)) {
if (ingredient != null && (repairMaterial == null || ingredient.getType() == repairMaterial) && (repairMetadata == -1 || ingredient.getData() == repairData)) {
quantity += ingredient.getAmount();
}
}
}
else if (recipe instanceof ShapedRecipe) {
for (ItemStack ingredient : ((ShapedRecipe) recipe).getIngredientMap().values()) {
if (ingredient != null && ingredient.getType() == repairMaterial && (repairMetadata == -1 || ingredient.getData() == repairData)) {
if (ingredient != null && (repairMaterial == null || ingredient.getType() == repairMaterial) && (repairMetadata == -1 || ingredient.getData() == repairData)) {
quantity += ingredient.getAmount();
}
}

View File

@ -136,6 +136,10 @@ public class RepairConfig extends ConfigLoader {
// Minimum Quantity
int minimumQuantity = (itemMaterial != null && repairMaterial != null ? Repair.getRepairAndSalvageQuantities(new ItemStack(itemMaterial), repairMaterial, repairMetadata) : config.getInt("Repairables." + key + ".MinimumQuantity"));
if (minimumQuantity <= 0 && itemMaterial != null) {
minimumQuantity = Repair.getRepairAndSalvageQuantities(new ItemStack(itemMaterial));
}
if (minimumQuantity <= 0) {
reason.add("Minimum quantity of " + key + " must be greater than 0!");
}