From d6fec167cb0fea34212e1d26fc54738a743e7a32 Mon Sep 17 00:00:00 2001 From: The_Fireplace Date: Mon, 21 Aug 2017 14:05:07 -0500 Subject: [PATCH 1/3] Properly handle invalid ItemStacks when rendering PageIRecipes --- .../guideapi/page/reciperenderer/ShapedRecipesRenderer.java | 5 +++++ .../page/reciperenderer/ShapelessRecipesRenderer.java | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapedRecipesRenderer.java b/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapedRecipesRenderer.java index 36e5591b..1ca08b88 100644 --- a/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapedRecipesRenderer.java +++ b/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapedRecipesRenderer.java @@ -5,6 +5,7 @@ import amerifrance.guideapi.api.impl.abstraction.EntryAbstract; import amerifrance.guideapi.api.util.GuiHelper; import amerifrance.guideapi.gui.GuiBase; +import amerifrance.guideapi.util.LogHelper; import net.minecraft.client.gui.FontRenderer; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.Ingredient; @@ -20,6 +21,7 @@ public ShapedRecipesRenderer(ShapedRecipes recipe) { super(recipe); } + @SuppressWarnings("ConstantConditions") @Override public void draw(Book book, CategoryAbstract category, EntryAbstract entry, int guiLeft, int guiTop, int mouseX, int mouseY, GuiBase guiBase, FontRenderer fontRendererObj) { super.draw(book, category, entry, guiLeft, guiTop, mouseX, mouseY, guiBase, fontRendererObj); @@ -30,6 +32,9 @@ public void draw(Book book, CategoryAbstract category, EntryAbstract entry, int Ingredient ingredient = recipe.getIngredients().get(y * recipe.recipeWidth + x); List list = Arrays.asList(ingredient.getMatchingStacks()); + for(ItemStack testStack:list) + if(testStack == null || testStack.getItem() == null) + list.remove(testStack); if (!list.isEmpty()) { ItemStack stack = list.get(getRandomizedCycle(x + (y * 3), list.size())); if (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE) diff --git a/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapelessRecipesRenderer.java b/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapelessRecipesRenderer.java index 10733a3b..052350e1 100644 --- a/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapelessRecipesRenderer.java +++ b/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapelessRecipesRenderer.java @@ -21,6 +21,7 @@ public ShapelessRecipesRenderer(ShapelessRecipes recipe) { super(recipe); } + @SuppressWarnings("ConstantConditions") @Override public void draw(Book book, CategoryAbstract category, EntryAbstract entry, int guiLeft, int guiTop, int mouseX, int mouseY, GuiBase guiBase, FontRenderer fontRendererObj) { super.draw(book, category, entry, guiLeft, guiTop, mouseX, mouseY, guiBase, fontRendererObj); @@ -32,6 +33,9 @@ public void draw(Book book, CategoryAbstract category, EntryAbstract entry, int if (i < recipe.getIngredients().size()) { Ingredient ingredient = recipe.getIngredients().get(i); List list = Arrays.asList(ingredient.getMatchingStacks()); + for(ItemStack testStack:list) + if(testStack == null || testStack.getItem() == null) + list.remove(testStack); if (!list.isEmpty()) { ItemStack stack = list.get(getRandomizedCycle(x + (y * 3), list.size())); if (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE) From f6d72036b79a876ef53152b1ca0db357467b0339 Mon Sep 17 00:00:00 2001 From: The_Fireplace Date: Thu, 24 Aug 2017 17:46:11 -0500 Subject: [PATCH 2/3] Should fix ConcurrentModificationException --- .../guideapi/page/reciperenderer/ShapedRecipesRenderer.java | 5 ++++- .../page/reciperenderer/ShapelessRecipesRenderer.java | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapedRecipesRenderer.java b/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapedRecipesRenderer.java index 1ca08b88..e75a3a69 100644 --- a/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapedRecipesRenderer.java +++ b/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapedRecipesRenderer.java @@ -6,6 +6,7 @@ import amerifrance.guideapi.api.util.GuiHelper; import amerifrance.guideapi.gui.GuiBase; import amerifrance.guideapi.util.LogHelper; +import com.google.common.collect.Lists; import net.minecraft.client.gui.FontRenderer; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.Ingredient; @@ -32,9 +33,11 @@ public void draw(Book book, CategoryAbstract category, EntryAbstract entry, int Ingredient ingredient = recipe.getIngredients().get(y * recipe.recipeWidth + x); List list = Arrays.asList(ingredient.getMatchingStacks()); + List removeList = Lists.newArrayList(); for(ItemStack testStack:list) if(testStack == null || testStack.getItem() == null) - list.remove(testStack); + removeList.add(testStack); + list.removeAll(removeList); if (!list.isEmpty()) { ItemStack stack = list.get(getRandomizedCycle(x + (y * 3), list.size())); if (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE) diff --git a/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapelessRecipesRenderer.java b/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapelessRecipesRenderer.java index 052350e1..51f2f1cc 100644 --- a/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapelessRecipesRenderer.java +++ b/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapelessRecipesRenderer.java @@ -6,6 +6,7 @@ import amerifrance.guideapi.api.util.GuiHelper; import amerifrance.guideapi.api.util.TextHelper; import amerifrance.guideapi.gui.GuiBase; +import com.google.common.collect.Lists; import net.minecraft.client.gui.FontRenderer; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.Ingredient; @@ -33,9 +34,11 @@ public void draw(Book book, CategoryAbstract category, EntryAbstract entry, int if (i < recipe.getIngredients().size()) { Ingredient ingredient = recipe.getIngredients().get(i); List list = Arrays.asList(ingredient.getMatchingStacks()); + List removeList = Lists.newArrayList(); for(ItemStack testStack:list) if(testStack == null || testStack.getItem() == null) - list.remove(testStack); + removeList.add(testStack); + list.removeAll(removeList); if (!list.isEmpty()) { ItemStack stack = list.get(getRandomizedCycle(x + (y * 3), list.size())); if (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE) From 7de09d11c4f20fb9fdbd0ae14057a0b7922d140d Mon Sep 17 00:00:00 2001 From: The_Fireplace Date: Sat, 1 Sep 2018 22:38:34 -0500 Subject: [PATCH 3/3] Use iterator in the list --- .../page/reciperenderer/ShapedRecipesRenderer.java | 7 +++++-- .../page/reciperenderer/ShapelessRecipesRenderer.java | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapedRecipesRenderer.java b/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapedRecipesRenderer.java index e75a3a69..f518ebc7 100644 --- a/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapedRecipesRenderer.java +++ b/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapedRecipesRenderer.java @@ -14,6 +14,7 @@ import net.minecraftforge.oredict.OreDictionary; import java.util.Arrays; +import java.util.Iterator; import java.util.List; public class ShapedRecipesRenderer extends BasicRecipeRenderer { @@ -34,9 +35,11 @@ public void draw(Book book, CategoryAbstract category, EntryAbstract entry, int Ingredient ingredient = recipe.getIngredients().get(y * recipe.recipeWidth + x); List list = Arrays.asList(ingredient.getMatchingStacks()); List removeList = Lists.newArrayList(); - for(ItemStack testStack:list) - if(testStack == null || testStack.getItem() == null) + for (Iterator iterator = list.iterator(); iterator.hasNext(); ) { + ItemStack testStack = iterator.next(); + if (testStack == null || testStack.getItem() == null) removeList.add(testStack); + } list.removeAll(removeList); if (!list.isEmpty()) { ItemStack stack = list.get(getRandomizedCycle(x + (y * 3), list.size())); diff --git a/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapelessRecipesRenderer.java b/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapelessRecipesRenderer.java index 51f2f1cc..e8826f42 100644 --- a/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapelessRecipesRenderer.java +++ b/src/main/java/amerifrance/guideapi/page/reciperenderer/ShapelessRecipesRenderer.java @@ -14,6 +14,7 @@ import net.minecraftforge.oredict.OreDictionary; import java.util.Arrays; +import java.util.Iterator; import java.util.List; public class ShapelessRecipesRenderer extends BasicRecipeRenderer { @@ -35,9 +36,11 @@ public void draw(Book book, CategoryAbstract category, EntryAbstract entry, int Ingredient ingredient = recipe.getIngredients().get(i); List list = Arrays.asList(ingredient.getMatchingStacks()); List removeList = Lists.newArrayList(); - for(ItemStack testStack:list) - if(testStack == null || testStack.getItem() == null) + for (Iterator iterator = list.iterator(); iterator.hasNext(); ) { + ItemStack testStack = iterator.next(); + if (testStack == null || testStack.getItem() == null) removeList.add(testStack); + } list.removeAll(removeList); if (!list.isEmpty()) { ItemStack stack = list.get(getRandomizedCycle(x + (y * 3), list.size()));