From fef9f9692f5f5e494910e81af7ffd677c3e3e0f9 Mon Sep 17 00:00:00 2001 From: t00thpick1 Date: Sun, 5 Jan 2014 00:41:06 -0500 Subject: [PATCH] [Bleeding] Check that vanilla recipes actually exist. Fixes BUKKIT-5277 When falling back to vanilla recipes in the iteration of recipes, a check is necessary to ensure that vanilla recipes are present. RecipeIterator has been modified to account for the multi-map setup. --- .../net/minecraft/server/RecipesFurnace.java | 2 +- .../craftbukkit/inventory/RecipeIterator.java | 23 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/minecraft/server/RecipesFurnace.java b/src/main/java/net/minecraft/server/RecipesFurnace.java index 44a621dbc5..bf6ddb4d2b 100644 --- a/src/main/java/net/minecraft/server/RecipesFurnace.java +++ b/src/main/java/net/minecraft/server/RecipesFurnace.java @@ -80,7 +80,7 @@ public class RecipesFurnace { do { if (!iterator.hasNext()) { // CraftBukkit start - if (!vanilla) { + if (!vanilla && recipes.size() != 0) { iterator = this.recipes.entrySet().iterator(); vanilla = true; } else { diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/RecipeIterator.java b/src/main/java/org/bukkit/craftbukkit/inventory/RecipeIterator.java index 568b2d0885..53b53b799e 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/RecipeIterator.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/RecipeIterator.java @@ -10,20 +10,18 @@ import net.minecraft.server.RecipesFurnace; public class RecipeIterator implements Iterator { private final Iterator recipes; - private final Iterator smelting; + private final Iterator smeltingCustom; + private final Iterator smeltingVanilla; private Iterator removeFrom = null; public RecipeIterator() { this.recipes = CraftingManager.getInstance().getRecipes().iterator(); - this.smelting = RecipesFurnace.getInstance().getRecipes().keySet().iterator(); + this.smeltingCustom = RecipesFurnace.getInstance().customRecipes.keySet().iterator(); + this.smeltingVanilla = RecipesFurnace.getInstance().recipes.keySet().iterator(); } public boolean hasNext() { - if (recipes.hasNext()) { - return true; - } else { - return smelting.hasNext(); - } + return recipes.hasNext() || smeltingCustom.hasNext() || smeltingVanilla.hasNext(); } public Recipe next() { @@ -31,8 +29,15 @@ public class RecipeIterator implements Iterator { removeFrom = recipes; return recipes.next().toBukkitRecipe(); } else { - removeFrom = smelting; - net.minecraft.server.ItemStack item = smelting.next(); + net.minecraft.server.ItemStack item; + if (smeltingCustom.hasNext()) { + removeFrom = smeltingCustom; + item = smeltingCustom.next(); + } else { + removeFrom = smeltingVanilla; + item = smeltingVanilla.next(); + } + CraftItemStack stack = CraftItemStack.asCraftMirror(RecipesFurnace.getInstance().getResult(item)); return new CraftFurnaceRecipe(stack, CraftItemStack.asCraftMirror(item));