Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly handle invalid ItemStacks when rendering PageIRecipes #96

Open
wants to merge 3 commits into
base: 1.12
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
import amerifrance.guideapi.api.impl.abstraction.EntryAbstract;
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;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraftforge.oredict.OreDictionary;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

public class ShapedRecipesRenderer extends BasicRecipeRenderer<ShapedRecipes> {
Expand All @@ -20,6 +23,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);
Expand All @@ -30,6 +34,13 @@ public void draw(Book book, CategoryAbstract category, EntryAbstract entry, int

Ingredient ingredient = recipe.getIngredients().get(y * recipe.recipeWidth + x);
List<ItemStack> list = Arrays.asList(ingredient.getMatchingStacks());
List<ItemStack> removeList = Lists.newArrayList();
for (Iterator<ItemStack> 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()));
if (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
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;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraftforge.oredict.OreDictionary;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

public class ShapelessRecipesRenderer extends BasicRecipeRenderer<ShapelessRecipes> {
Expand All @@ -21,6 +23,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);
Expand All @@ -32,6 +35,13 @@ public void draw(Book book, CategoryAbstract category, EntryAbstract entry, int
if (i < recipe.getIngredients().size()) {
Ingredient ingredient = recipe.getIngredients().get(i);
List<ItemStack> list = Arrays.asList(ingredient.getMatchingStacks());
List<ItemStack> removeList = Lists.newArrayList();
for (Iterator<ItemStack> 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()));
if (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE)
Expand Down