diff --git a/build.properties b/build.properties index 5ec01980..0dbe19e3 100644 --- a/build.properties +++ b/build.properties @@ -1,5 +1,5 @@ # -#Mon Mar 02 18:09:06 EST 2015 +#Tue Mar 03 18:39:06 EST 2015 mod_name=BloodMagic forge_version=10.13.2.1232 ccc_version=1.0.4.29 @@ -8,5 +8,5 @@ nei_version=1.0.3.64 package_group=com.wayoftime.bloodmagic mod_version=1.3.1 minetweaker_version=Dev-1.7.10-3.0.9B +build_number=7 mc_version=1.7.10 -build_number=6 diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingManager.java b/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingManager.java index f6ae97fb..7c104468 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingManager.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingManager.java @@ -8,7 +8,6 @@ import net.minecraft.inventory.Container; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.ShapedRecipes; import net.minecraft.item.crafting.ShapelessRecipes; @@ -29,12 +28,13 @@ public class StorageBlockCraftingManager public void addStorageBlockRecipes() { - List list = CraftingManager.getInstance().getRecipeList(); + this.recipes = new StorageBlockCraftingRecipeAssimilator().getPackingOptions(); + List tempRecipeList = new LinkedList(); World world = DimensionManager.getWorld(0); - for(Object obj : list) + for(Object obj : this.recipes) { if(obj instanceof IRecipe) { @@ -93,11 +93,11 @@ public class StorageBlockCraftingManager tempRecipeList.add(recipe); continue; } - - } } - + + List tempRecipeList2 = new LinkedList(); + for(Object obj : tempRecipeList) { if(obj instanceof IRecipe) @@ -111,14 +111,16 @@ public class StorageBlockCraftingManager if(isResultStackReversible(outputStack, 2, world, tempRecipeList) || isResultStackReversible(outputStack, 3, world, tempRecipeList)) { - recipes.add(recipe); + tempRecipeList2.add(recipe); AlchemicalWizardry.logger.info("Now adding recipe for " + outputStack + " to the compression handler."); } } } + + this.recipes = tempRecipeList2; } - public static boolean isResultStackReversible(ItemStack stack, int gridSize, World world, List list) + private static boolean isResultStackReversible(ItemStack stack, int gridSize, World world, List list) { if(stack == null) { @@ -160,7 +162,7 @@ public class StorageBlockCraftingManager } } - public static ItemStack getRecipe(ItemStack stack, World world, int gridSize, List list) + private static ItemStack getRecipe(ItemStack stack, World world, int gridSize, List list) { InventoryCrafting inventory = new InventoryCrafting(new Container() { @@ -177,22 +179,22 @@ public class StorageBlockCraftingManager return StorageBlockCraftingManager.getInstance().findMatchingRecipe(inventory, world, list); } - public static boolean has22Recipe(ItemStack stack, World world, List list) + private static boolean has22Recipe(ItemStack stack, World world, List list) { return get22Recipe(stack, world, list) != null; } - public static ItemStack get22Recipe(ItemStack stack, World world, List list) + private static ItemStack get22Recipe(ItemStack stack, World world, List list) { return getRecipe(stack, world, 2, list); } - public static boolean has33Recipe(ItemStack stack, World world, List list) + private static boolean has33Recipe(ItemStack stack, World world, List list) { return get33Recipe(stack, world, list) != null; } - public static ItemStack get33Recipe(ItemStack stack, World world, List list) + private static ItemStack get33Recipe(ItemStack stack, World world, List list) { return getRecipe(stack, world, 3, list); } @@ -202,7 +204,7 @@ public class StorageBlockCraftingManager return this.findMatchingRecipe(p_82787_1_, p_82787_2_, this.recipes); } - public ItemStack findMatchingRecipe(InventoryCrafting p_82787_1_, World p_82787_2_, List list) + private ItemStack findMatchingRecipe(InventoryCrafting p_82787_1_, World p_82787_2_, List list) { int i = 0; ItemStack itemstack = null; diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingRecipeAssimilator.java b/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingRecipeAssimilator.java new file mode 100644 index 00000000..fe21f0f4 --- /dev/null +++ b/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingRecipeAssimilator.java @@ -0,0 +1,132 @@ +package WayofTime.alchemicalWizardry.common.compress; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.item.crafting.ShapedRecipes; +import net.minecraft.item.crafting.ShapelessRecipes; +import net.minecraftforge.oredict.OreDictionary; +import net.minecraftforge.oredict.ShapedOreRecipe; +import net.minecraftforge.oredict.ShapelessOreRecipe; + +public class StorageBlockCraftingRecipeAssimilator +{ + public List getPackingOptions() + { + List packingRecipes = new ArrayList(); + List unpackingRecipes = new ArrayList(); + + List returnedRecipes = new ArrayList(); + + for (IRecipe recipe : getCraftingRecipes()) { + ItemStack output = recipe.getRecipeOutput(); + if (output == null || output.getItem() == null) continue; + + if (output.stackSize == 1 && isPossiblePackingRecipe(recipe)) { + packingRecipes.add(recipe); + } else if ((output.stackSize == 4 || output.stackSize == 9) && recipe.getRecipeSize() == 1) { + unpackingRecipes.add(recipe); + } + } + + packingRecipes.addAll(unpackingRecipes); + + return packingRecipes; + } + + @SuppressWarnings("unchecked") + private List getCraftingRecipes() { + return CraftingManager.getInstance().getRecipeList(); + } + + private Container makeDummyContainer() { + return new Container() { + @Override + public boolean canInteractWith(EntityPlayer p_75145_1_) { + return true; + } + }; + } + + private boolean isPossiblePackingRecipe(IRecipe recipe) { + if (recipe.getRecipeSize() < 4) return false; + + List inputs; + + if (recipe instanceof ShapedRecipes) { + inputs = Arrays.asList(((ShapedRecipes) recipe).recipeItems); + } else if (recipe instanceof ShapelessRecipes) { + inputs = ((ShapelessRecipes) recipe).recipeItems; + } else if (recipe instanceof ShapedOreRecipe) { + inputs = Arrays.asList(((ShapedOreRecipe) recipe).getInput()); + } else if (recipe instanceof ShapelessOreRecipe) { + inputs = ((ShapelessOreRecipe) recipe).getInput(); + } else { + return true; + } + + return areInputsIdentical(inputs); + } + + @SuppressWarnings("unchecked") + private boolean areInputsIdentical(List inputs) { + List options = null; + + for (Object input : inputs) { + if (input == null) continue; + + List offers; + + if (input instanceof ItemStack) { + offers = Arrays.asList((ItemStack) input); + } else if (input instanceof List) { + offers = (List) input; + + if (offers.isEmpty()) return false; + } else { + throw new RuntimeException("invalid input: "+input.getClass()); + } + + if (options == null) { + options = new ArrayList(offers); + continue; + } + + for (Iterator it = options.iterator(); it.hasNext(); ) { + ItemStack stackReq = it.next(); + boolean found = false; + + for (ItemStack stackCmp : offers) { + if (areInputsIdentical(stackReq, stackCmp)) { + found = true; + break; + } + } + + if (!found) { + it.remove(); + + if (options.isEmpty()) return false; + } + } + } + + return true; + } + + private boolean areInputsIdentical(ItemStack a, ItemStack b) { + if (a.getItem() != b.getItem()) return false; + + int dmgA = a.getItemDamage(); + int dmgB = b.getItemDamage(); + + return dmgA == dmgB || dmgA == OreDictionary.WILDCARD_VALUE || dmgB == OreDictionary.WILDCARD_VALUE; + } +} \ No newline at end of file