From 8fbb19acc0363c0f342b8114e2a451df31017ea3 Mon Sep 17 00:00:00 2001 From: WayofTime Date: Thu, 26 Feb 2015 17:32:53 -0500 Subject: [PATCH] Fully optimized the compression handler~ --- .../AlchemicalWizardry.java | 6 +- .../api/tile/IBloodAltar.java | 4 + .../compress/AdvancedCompressionHandler.java | 21 +- .../compress/StorageBlockCraftingManager.java | 187 ++++++++++++++++++ .../common/items/SacrificialDagger.java | 22 +-- 5 files changed, 217 insertions(+), 23 deletions(-) create mode 100644 src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingManager.java diff --git a/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java b/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java index 5e1fd37b..7362ad05 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java +++ b/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java @@ -74,6 +74,7 @@ import WayofTime.alchemicalWizardry.common.commands.CommandSN; import WayofTime.alchemicalWizardry.common.commands.CommandUnbind; import WayofTime.alchemicalWizardry.common.compress.AdvancedCompressionHandler; import WayofTime.alchemicalWizardry.common.compress.BaseCompressionHandler; +import WayofTime.alchemicalWizardry.common.compress.StorageBlockCraftingManager; import WayofTime.alchemicalWizardry.common.demonVillage.demonHoard.DemonPacketMinorGrunt; import WayofTime.alchemicalWizardry.common.demonVillage.demonHoard.DemonPacketRegistry; import WayofTime.alchemicalWizardry.common.demonVillage.demonHoard.demon.EntityMinorDemonGrunt; @@ -797,7 +798,6 @@ public class AlchemicalWizardry this.initDemonPacketRegistiry(); this.initiateRegistry(); - this.initCompressionHandlers(); this.blacklistDemons(); @@ -1188,6 +1188,9 @@ public class AlchemicalWizardry DemonVillageLootRegistry.init(); + this.initCompressionHandlers(); + + // if(parseTextFiles) // this.parseTextFile(); @@ -1496,6 +1499,7 @@ public class AlchemicalWizardry public void initCompressionHandlers() { + StorageBlockCraftingManager.getInstance().addStorageBlockRecipes(); CompressionRegistry.registerHandler(new BaseCompressionHandler(new ItemStack(Items.glowstone_dust, 4, 0), new ItemStack(Blocks.glowstone), 64)); CompressionRegistry.registerHandler(new AdvancedCompressionHandler()); diff --git a/src/main/java/WayofTime/alchemicalWizardry/api/tile/IBloodAltar.java b/src/main/java/WayofTime/alchemicalWizardry/api/tile/IBloodAltar.java index c70d6188..d190dae4 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/api/tile/IBloodAltar.java +++ b/src/main/java/WayofTime/alchemicalWizardry/api/tile/IBloodAltar.java @@ -23,4 +23,8 @@ public interface IBloodAltar public float getDislocationMultiplier(); public int getBufferCapacity(); + + public void sacrificialDaggerCall(int amount, boolean b); + + public void startCycle(); } diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/compress/AdvancedCompressionHandler.java b/src/main/java/WayofTime/alchemicalWizardry/common/compress/AdvancedCompressionHandler.java index 4ffd25c3..61a62a89 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/compress/AdvancedCompressionHandler.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/compress/AdvancedCompressionHandler.java @@ -4,7 +4,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.CraftingManager; import net.minecraft.world.World; import WayofTime.alchemicalWizardry.api.compress.CompressionHandler; import WayofTime.alchemicalWizardry.api.compress.CompressionRegistry; @@ -30,7 +29,7 @@ public class AdvancedCompressionHandler extends CompressionHandler for(int i=2; i<=3; i++) { ItemStack stacky = getRecipe(invStack, world, i); - if(isResultStackReversible(stacky, i, world)) + if(stacky!=null) { int threshold = CompressionRegistry.getItemThreshold(invStack); @@ -98,7 +97,7 @@ public class AdvancedCompressionHandler extends CompressionHandler return needed; } - public boolean isResultStackReversible(ItemStack stack, int gridSize, World world) + public static boolean isResultStackReversible(ItemStack stack, int gridSize, World world) { if(stack == null) { @@ -114,7 +113,7 @@ public class AdvancedCompressionHandler extends CompressionHandler inventory.setInventorySlotContents(0, stack); - ItemStack returnStack = CraftingManager.getInstance().findMatchingRecipe(inventory, world); + ItemStack returnStack = StorageBlockCraftingManager.getInstance().findMatchingRecipe(inventory, world); if(returnStack == null) { return false; @@ -140,7 +139,7 @@ public class AdvancedCompressionHandler extends CompressionHandler } } - public ItemStack getRecipe(ItemStack stack, World world, int gridSize) + public static ItemStack getRecipe(ItemStack stack, World world, int gridSize) { InventoryCrafting inventory = new InventoryCrafting(new Container() { @@ -154,25 +153,25 @@ public class AdvancedCompressionHandler extends CompressionHandler inventory.setInventorySlotContents(i, stack); } - return CraftingManager.getInstance().findMatchingRecipe(inventory, world); + return StorageBlockCraftingManager.getInstance().findMatchingRecipe(inventory, world); } - public boolean has22Recipe(ItemStack stack, World world) + public static boolean has22Recipe(ItemStack stack, World world) { return get22Recipe(stack, world) != null; } - public ItemStack get22Recipe(ItemStack stack, World world) + public static ItemStack get22Recipe(ItemStack stack, World world) { return getRecipe(stack, world, 2); } - public boolean has33Recipe(ItemStack stack, World world) + public static boolean has33Recipe(ItemStack stack, World world) { - return get22Recipe(stack, world) != null; + return get33Recipe(stack, world) != null; } - public ItemStack get33Recipe(ItemStack stack, World world) + public static ItemStack get33Recipe(ItemStack stack, World world) { return getRecipe(stack, world, 3); } diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingManager.java b/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingManager.java new file mode 100644 index 00000000..78c6e08e --- /dev/null +++ b/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingManager.java @@ -0,0 +1,187 @@ +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) + { + 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