Permalink
Browse files

More filtering for invalid recipes. Also added a warning for when cer…

…tain ones are found.
  • Loading branch information...
me4502 committed Dec 29, 2016
1 parent 76d802e commit 77b87c9fdc5aef1eef1fbf5ca03026f0b8f5756c
@@ -1,10 +1,14 @@
package com.sk89q.craftbook.mechanics.ic.gates.world.items;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
+import com.sk89q.craftbook.ChangedSign;
+import com.sk89q.craftbook.bukkit.CraftBookPlugin;
+import com.sk89q.craftbook.bukkit.util.BukkitUtil;
+import com.sk89q.craftbook.mechanics.crafting.CustomCrafting;
+import com.sk89q.craftbook.mechanics.ic.*;
+import com.sk89q.craftbook.mechanics.pipe.PipePutEvent;
+import com.sk89q.craftbook.mechanics.pipe.PipeRequestEvent;
+import com.sk89q.craftbook.util.ItemUtil;
+import com.sk89q.craftbook.util.VerifyUtil;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Server;
@@ -13,30 +17,17 @@
import org.bukkit.block.Dispenser;
import org.bukkit.block.Dropper;
import org.bukkit.entity.Item;
-import org.bukkit.inventory.Inventory;
-import org.bukkit.inventory.InventoryHolder;
-import org.bukkit.inventory.ItemStack;
-import org.bukkit.inventory.Recipe;
-import org.bukkit.inventory.ShapedRecipe;
-import org.bukkit.inventory.ShapelessRecipe;
+import org.bukkit.inventory.*;
-import com.sk89q.craftbook.ChangedSign;
-import com.sk89q.craftbook.bukkit.CraftBookPlugin;
-import com.sk89q.craftbook.bukkit.util.BukkitUtil;
-import com.sk89q.craftbook.mechanics.crafting.CustomCrafting;
-import com.sk89q.craftbook.mechanics.ic.AbstractICFactory;
-import com.sk89q.craftbook.mechanics.ic.AbstractSelfTriggeredIC;
-import com.sk89q.craftbook.mechanics.ic.ChipState;
-import com.sk89q.craftbook.mechanics.ic.IC;
-import com.sk89q.craftbook.mechanics.ic.ICFactory;
-import com.sk89q.craftbook.mechanics.ic.PipeInputIC;
-import com.sk89q.craftbook.mechanics.pipe.PipePutEvent;
-import com.sk89q.craftbook.mechanics.pipe.PipeRequestEvent;
-import com.sk89q.craftbook.util.ItemUtil;
-import com.sk89q.craftbook.util.VerifyUtil;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
public class AutomaticCrafter extends AbstractSelfTriggeredIC implements PipeInputIC {
+ private static boolean hasWarned = false;
+
public AutomaticCrafter(Server server, ChangedSign block, ICFactory factory) {
super(server, block, factory);
@@ -81,13 +72,13 @@ public boolean craft(InventoryHolder disp) {
}
if (recipe == null) {
-
Iterator<Recipe> recipes = Bukkit.recipeIterator();
try {
while (recipes.hasNext()) {
Recipe temprecipe = recipes.next();
if (isValidRecipe(temprecipe, inv)) {
recipe = temprecipe;
+ break; //There should only be 1 valid recipe.
}
}
} catch (Exception e) {
@@ -106,7 +97,7 @@ public boolean craft(InventoryHolder disp) {
ItemStack result = CustomCrafting.craftItem(recipe);
if(!ItemUtil.isStackValid(result)) {
- CraftBookPlugin.inst().getLogger().warning("An Automatic Crafter IC had a valid recipe, but there was no result!");
+ CraftBookPlugin.inst().getLogger().warning("An Automatic Crafter IC had a valid recipe, but there was no result! This means Bukkit has an invalid recipe!");
return false;
}
@@ -211,6 +202,7 @@ private boolean isValidRecipe(Recipe r, Inventory inv) {
String[] shapeArr = shape.getShape();
if (shape.getShape().length != shapeArr.length || shapeArr[0].length() != shape.getShape()[0].length()) return false;
int c = -1, in = 0;
+ int validRecipeItems = 0;
for (int slot = 0; slot < 9; slot++) {
ItemStack stack = inv.getItem(slot);
try {
@@ -242,13 +234,22 @@ private boolean isValidRecipe(Recipe r, Inventory inv) {
catch(Exception e){
BukkitUtil.printStacktrace(e);
}
+ if (require != null && require.getType() != Material.AIR) {
+ validRecipeItems ++;
+ }
if (!ItemUtil.areItemsIdentical(require, stack))
return false;
} catch (Exception e) {
BukkitUtil.printStacktrace(e);
return false;
}
}
+ if (validRecipeItems == 0 && !hasWarned) {
+ CraftBookPlugin.logger().warning("Found invalid recipe! This is an issue with Bukkit/Spigot/etc, please report to them. All recipe ingredients are air. Recipe result: " + recipe.getResult().toString());
+ hasWarned = true;
+ return false;
+ }
+
return true;
} else if (r instanceof ShapelessRecipe && (recipe == null || recipe instanceof ShapelessRecipe)) {
ShapelessRecipe shape = (ShapelessRecipe) r;

0 comments on commit 77b87c9

Please sign in to comment.