package WayofTime.alchemicalWizardry.common.compress; import java.util.ArrayList; import java.util.List; import net.minecraft.entity.player.EntityPlayer; 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.world.World; import net.minecraftforge.common.DimensionManager; import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper; public class StorageBlockCraftingManager { private static final StorageBlockCraftingManager instance = new StorageBlockCraftingManager(); private List recipes = new ArrayList(); public static StorageBlockCraftingManager getInstance() { return instance; } public void addStorageBlockRecipes() { List list = CraftingManager.getInstance().getRecipeList(); World world = DimensionManager.getWorld(0); for(Object obj : list) { if(obj instanceof IRecipe) { IRecipe recipe = (IRecipe)obj; ItemStack outputStack = recipe.getRecipeOutput(); if(outputStack == null || outputStack.getItem() == null) { continue; } if(isResultStackReversible(outputStack, 2, world) || isResultStackReversible(outputStack, 3, world)) { recipes.add(recipe); } } } } public static boolean isResultStackReversible(ItemStack stack, int gridSize, World world) { if(stack == null) { return false; } InventoryCrafting inventory = new InventoryCrafting(new Container() { public boolean canInteractWith(EntityPlayer player) { return false; } }, 2, 2); inventory.setInventorySlotContents(0, stack); ItemStack returnStack = CraftingManager.getInstance().findMatchingRecipe(inventory, world); if(returnStack == null) { return false; } ItemStack compressedStack = null; switch(gridSize) { case 2: compressedStack = get22Recipe(returnStack, world); break; case 3: compressedStack = get33Recipe(returnStack, world); break; } if(compressedStack == null) { return false; }else { return SpellHelper.areItemStacksEqual(stack, compressedStack); } } public static ItemStack getRecipe(ItemStack stack, World world, int gridSize) { InventoryCrafting inventory = new InventoryCrafting(new Container() { public boolean canInteractWith(EntityPlayer player) { return false; } }, gridSize, gridSize); for(int i=0; i