diff --git a/src/main/java/forestry/core/recipes/RecipeUtil.java b/src/main/java/forestry/core/recipes/RecipeUtil.java index b8c4db81c..edd029665 100644 --- a/src/main/java/forestry/core/recipes/RecipeUtil.java +++ b/src/main/java/forestry/core/recipes/RecipeUtil.java @@ -110,10 +110,37 @@ public abstract class RecipeUtil { // in place of the ones in the saved crafting inventory. // Check that the recipe it makes is the same as the currentRecipe. InventoryCraftingForestry crafting = new InventoryCraftingForestry(); - ItemStack[] stockCopy = ItemStackUtil.condenseStacks(availableItems); + final ItemStack[] ingregients = RecipeUtil.getCraftIngredients(recipeItems, availableItems); + + for (int slot = 0; slot < ingregients.length; slot++) { + ItemStack recipeStack = ingregients[slot]; + + if (recipeStack == null && recipeItems[slot] != null) { + return null; + } + + if (recipeStack == null) { + continue; + } + + crafting.setInventorySlotContents(slot, recipeStack); + } + + List outputs = findMatchingRecipes(crafting, world); + if (!ItemStackUtil.containsItemStack(outputs, recipeOutput)) { + return null; + } + return crafting; + } + + public static ItemStack[] getCraftIngredients(ItemStack[] recipeItems, ItemStack[] availableItems) + { + final ItemStack[] stockCopy = ItemStackUtil.condenseStacks(availableItems); + final ItemStack[] ingredients = new ItemStack[recipeItems.length]; for (int slot = 0; slot < recipeItems.length; slot++) { ItemStack recipeStack = recipeItems[slot]; + if (recipeStack == null) { continue; } @@ -121,30 +148,26 @@ public abstract class RecipeUtil { // Use crafting equivalent (not oredict) items first for (ItemStack stockStack : stockCopy) { if (stockStack.stackSize > 0 && ItemStackUtil.isCraftingEquivalent(recipeStack, stockStack, false, false)) { - ItemStack stack = ItemStackUtil.createSplitStack(stockStack, 1); + ingredients[slot] = ItemStackUtil.createSplitStack(stockStack, 1); stockStack.stackSize--; - crafting.setInventorySlotContents(slot, stack); break; } } // Use oredict items if crafting equivalent items aren't available - if (crafting.getStackInSlot(slot) == null) { + if (ingredients[slot] == null) { for (ItemStack stockStack : stockCopy) { if (stockStack.stackSize > 0 && ItemStackUtil.isCraftingEquivalent(recipeStack, stockStack, true, true)) { - ItemStack stack = ItemStackUtil.createSplitStack(stockStack, 1); + ingredients[slot] = ItemStackUtil.createSplitStack(stockStack, 1); stockStack.stackSize--; - crafting.setInventorySlotContents(slot, stack); break; } } } + } - List outputs = findMatchingRecipes(crafting, world); - if (!ItemStackUtil.containsItemStack(outputs, recipeOutput)) { - return null; - } - return crafting; + + return ingredients; } public static List findMatchingRecipes(InventoryCrafting inventory, World world) { diff --git a/src/main/java/forestry/factory/gui/GuiWorktable.java b/src/main/java/forestry/factory/gui/GuiWorktable.java index 44d4af42b..e01b06df0 100755 --- a/src/main/java/forestry/factory/gui/GuiWorktable.java +++ b/src/main/java/forestry/factory/gui/GuiWorktable.java @@ -12,18 +12,25 @@ package forestry.factory.gui; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; - +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; import forestry.core.config.Constants; import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.buttons.GuiBetterButton; import forestry.core.gui.buttons.StandardButtonTextureSets; import forestry.core.network.packets.PacketGuiSelectRequest; import forestry.core.proxy.Proxies; +import forestry.core.recipes.RecipeUtil; +import forestry.core.utils.InventoryUtil; import forestry.factory.gui.widgets.ClearWorktable; import forestry.factory.gui.widgets.MemorizedRecipeSlot; +import forestry.factory.inventory.InventoryGhostCrafting; +import forestry.factory.recipes.MemorizedRecipe; import forestry.factory.recipes.RecipeMemory; import forestry.factory.tiles.TileWorktable; +import org.lwjgl.opengl.GL11; + public class GuiWorktable extends GuiForestryTitled { private static final int SPACING = 18; private boolean hasRecipeConflict = false; @@ -62,6 +69,49 @@ public class GuiWorktable extends GuiForestryTitled