From d32b39d8c601dd8c8dda7d6f3ce2945595fd08ef Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sat, 16 May 2015 17:23:39 +0100 Subject: [PATCH] Machines no longer require an input in the set slot --- build.gradle | 2 +- .../techreborn/api/recipe/RecipeCrafter.java | 55 ++++++++++++++----- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/build.gradle b/build.gradle index cdddcdf0e..6257130f5 100644 --- a/build.gradle +++ b/build.gradle @@ -51,7 +51,7 @@ if (ENV.BUILD_NUMBER) { } minecraft { - version = "1.7.10-10.13.3.1394-1710ls" + version = "1.7.10-10.13.3.1403-1.7.10" replace "@MODVERSION@", project.version replaceIn "ModInfo.java" replaceIn "package-info.java" diff --git a/src/main/java/techreborn/api/recipe/RecipeCrafter.java b/src/main/java/techreborn/api/recipe/RecipeCrafter.java index 32ff3987c..398f04081 100644 --- a/src/main/java/techreborn/api/recipe/RecipeCrafter.java +++ b/src/main/java/techreborn/api/recipe/RecipeCrafter.java @@ -1,6 +1,7 @@ package techreborn.api.recipe; import ic2.api.energy.prefab.BasicSink; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import techreborn.tiles.TileMachineBase; @@ -87,26 +88,16 @@ public class RecipeCrafter { public void updateEntity() { if (currentRecipe == null) { for (IBaseRecipeType recipe : RecipeHanderer.getRecipeClassFromName(recipeName)) { - boolean isFullRecipe = false; - for (int i = 0; i < inputs; i++) { - if (ItemUtils.isItemEqual(inventory.getStackInSlot(inputSlots[i]), recipe.getInputs().get(i), true, true, true) && inventory.getStackInSlot(inputSlots[i]).stackSize >= recipe.getInputs().get(i).stackSize) { - isFullRecipe = true; - } else { - isFullRecipe = false; - } - } - if (isFullRecipe) { + if(hasAllInputs(recipe)){ currentRecipe = recipe; return; } } } else { - for (int i = 0; i < inputs; i++) { - if (!ItemUtils.isItemEqual(inventory.getStackInSlot(inputSlots[i]), currentRecipe.getInputs().get(i), true, true, true) || (inventory.getStackInSlot(inputSlots[i]) == null || (inventory.getStackInSlot(inputSlots[i]).stackSize < currentRecipe.getInputs().get(i).stackSize))) { - currentRecipe = null; - currentTickTime = 0; - return; - } + if(!hasAllInputs()){ + currentRecipe = null; + currentTickTime = 0; + return; } if (currentTickTime >= currentRecipe.tickTime()) { boolean canGiveInvAll = true; @@ -141,6 +132,40 @@ public class RecipeCrafter { } } + public boolean hasAllInputs(){ + if(currentRecipe == null){ + return false; + } + for(ItemStack input : currentRecipe.getInputs()){ + Boolean hasItem = false; + for(int inputslot : inputSlots){ + if(ItemUtils.isItemEqual(input, inventory.getStackInSlot(inputslot), true, true, true)){ + hasItem = true; + } + } + if(!hasItem) + return false; + } + return true; + } + + public boolean hasAllInputs(IBaseRecipeType recipeType){ + if(recipeType == null){ + return false; + } + for(ItemStack input : recipeType.getInputs()){ + Boolean hasItem = false; + for(int inputslot : inputSlots){ + if(ItemUtils.isItemEqual(input, inventory.getStackInSlot(inputslot), true, true, true)){ + hasItem = true; + } + } + if(!hasItem) + return false; + } + return true; + } + public boolean canFitStack(ItemStack stack, int slot) { if (stack == null) { return true;