diff --git a/build.properties b/build.properties index 0dbe19e3..1a774896 100644 --- a/build.properties +++ b/build.properties @@ -1,5 +1,5 @@ # -#Tue Mar 03 18:39:06 EST 2015 +#Wed Mar 04 17:54:09 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=8 diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingManager.java b/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingManager.java index 7c104468..6f52fefa 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingManager.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingManager.java @@ -9,11 +9,7 @@ import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; -import net.minecraft.item.crafting.ShapedRecipes; -import net.minecraft.item.crafting.ShapelessRecipes; import net.minecraft.world.World; -import net.minecraftforge.common.DimensionManager; -import WayofTime.alchemicalWizardry.AlchemicalWizardry; import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper; public class StorageBlockCraftingManager @@ -28,96 +24,97 @@ public class StorageBlockCraftingManager public void addStorageBlockRecipes() { - this.recipes = new StorageBlockCraftingRecipeAssimilator().getPackingOptions(); + this.recipes = new StorageBlockCraftingRecipeAssimilator().getPackingRecipes(); - List tempRecipeList = new LinkedList(); - - World world = DimensionManager.getWorld(0); - - for(Object obj : this.recipes) - { - if(obj instanceof IRecipe) - { - IRecipe recipe = (IRecipe)obj; - ItemStack outputStack = recipe.getRecipeOutput(); - if(outputStack == null || outputStack.getItem() == null) - { - continue; - } - - if(recipe instanceof ShapedRecipes) - { - ShapedRecipes sRecipe = (ShapedRecipes)recipe; - ItemStack[] input = sRecipe.recipeItems; - - if(outputStack.stackSize == 1 && (input.length == 9 || input.length == 4)) - { - tempRecipeList.add(recipe); - }else if((outputStack.stackSize == 9 || outputStack.stackSize == 4) && input.length == 1) - { - tempRecipeList.add(recipe); - } - } - else if(recipe instanceof ShapelessRecipes) - { - ShapelessRecipes sRecipe = (ShapelessRecipes)recipe; - List input = sRecipe.recipeItems; - - if(outputStack.stackSize == 1 && (input.size() == 9 || input.size() == 4)) - { - Object obj1 = input.get(0); - if(obj1 != null) - { - boolean allMatch = true; - for(Object obj2 : input) - { - if(obj2 == null || !obj2.equals(obj1)) - { - allMatch = false; - break; - } - } - if(allMatch) - { - tempRecipeList.add(recipe); - } - } - - }else if((outputStack.stackSize == 9 || outputStack.stackSize == 4) && input.size() == 1) - { - tempRecipeList.add(recipe); - } - } - else if((outputStack.stackSize == 1 && (recipe.getRecipeSize() == 9 || recipe.getRecipeSize() == 4)) || ((outputStack.stackSize == 9 || outputStack.stackSize == 4) && recipe.getRecipeSize() == 1)) - { - tempRecipeList.add(recipe); - continue; - } - } - } - - List tempRecipeList2 = new LinkedList(); - - for(Object obj : tempRecipeList) - { - if(obj instanceof IRecipe) - { - IRecipe recipe = (IRecipe)obj; - ItemStack outputStack = recipe.getRecipeOutput(); - if(outputStack == null || outputStack.getItem() == null) - { - continue; - } - - if(isResultStackReversible(outputStack, 2, world, tempRecipeList) || isResultStackReversible(outputStack, 3, world, tempRecipeList)) - { - tempRecipeList2.add(recipe); - AlchemicalWizardry.logger.info("Now adding recipe for " + outputStack + " to the compression handler."); - } - } - } - - this.recipes = tempRecipeList2; + System.out.println("Total number of compression recipes: " + this.recipes.size()); +// List tempRecipeList = new LinkedList(); +// +// World world = DimensionManager.getWorld(0); +// +// for(Object obj : this.recipes) +// { +// if(obj instanceof IRecipe) +// { +// IRecipe recipe = (IRecipe)obj; +// ItemStack outputStack = recipe.getRecipeOutput(); +// if(outputStack == null || outputStack.getItem() == null) +// { +// continue; +// } +// +// if(recipe instanceof ShapedRecipes) +// { +// ShapedRecipes sRecipe = (ShapedRecipes)recipe; +// ItemStack[] input = sRecipe.recipeItems; +// +// if(outputStack.stackSize == 1 && (input.length == 9 || input.length == 4)) +// { +// tempRecipeList.add(recipe); +// }else if((outputStack.stackSize == 9 || outputStack.stackSize == 4) && input.length == 1) +// { +// tempRecipeList.add(recipe); +// } +// } +// else if(recipe instanceof ShapelessRecipes) +// { +// ShapelessRecipes sRecipe = (ShapelessRecipes)recipe; +// List input = sRecipe.recipeItems; +// +// if(outputStack.stackSize == 1 && (input.size() == 9 || input.size() == 4)) +// { +// Object obj1 = input.get(0); +// if(obj1 != null) +// { +// boolean allMatch = true; +// for(Object obj2 : input) +// { +// if(obj2 == null || !obj2.equals(obj1)) +// { +// allMatch = false; +// break; +// } +// } +// if(allMatch) +// { +// tempRecipeList.add(recipe); +// } +// } +// +// }else if((outputStack.stackSize == 9 || outputStack.stackSize == 4) && input.size() == 1) +// { +// tempRecipeList.add(recipe); +// } +// } +// else if((outputStack.stackSize == 1 && (recipe.getRecipeSize() == 9 || recipe.getRecipeSize() == 4)) || ((outputStack.stackSize == 9 || outputStack.stackSize == 4) && recipe.getRecipeSize() == 1)) +// { +// tempRecipeList.add(recipe); +// continue; +// } +// } +// } +// +// List tempRecipeList2 = new LinkedList(); +// +// for(Object obj : tempRecipeList) +// { +// if(obj instanceof IRecipe) +// { +// IRecipe recipe = (IRecipe)obj; +// ItemStack outputStack = recipe.getRecipeOutput(); +// if(outputStack == null || outputStack.getItem() == null) +// { +// continue; +// } +// +// if(isResultStackReversible(outputStack, 2, world, tempRecipeList) || isResultStackReversible(outputStack, 3, world, tempRecipeList)) +// { +// tempRecipeList2.add(recipe); +// AlchemicalWizardry.logger.info("Now adding recipe for " + outputStack + " to the compression handler."); +// } +// } +// } +// +// this.recipes = tempRecipeList2; } private static boolean isResultStackReversible(ItemStack stack, int gridSize, World world, List list) diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingRecipeAssimilator.java b/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingRecipeAssimilator.java index fe21f0f4..7025d0f5 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingRecipeAssimilator.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingRecipeAssimilator.java @@ -3,42 +3,119 @@ package WayofTime.alchemicalWizardry.common.compress; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; +import WayofTime.alchemicalWizardry.AlchemicalWizardry; 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.item.crafting.IRecipe; import net.minecraft.item.crafting.ShapedRecipes; import net.minecraft.item.crafting.ShapelessRecipes; +import net.minecraft.world.World; 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(); +public class StorageBlockCraftingRecipeAssimilator { + public List getPackingRecipes() { + // grab all recipes potentially suitable for packing or unpacking + + List packingRecipes = new LinkedList(); 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); + if (output.stackSize == 1) { + PackingRecipe packingRecipe = getPackingRecipe(recipe); + + if (packingRecipe != null) { + packingRecipes.add(packingRecipe); + } } else if ((output.stackSize == 4 || output.stackSize == 9) && recipe.getRecipeSize() == 1) { unpackingRecipes.add(recipe); } } - packingRecipes.addAll(unpackingRecipes); - - return packingRecipes; + // grab all packing recipes which accept the output of any of the unpacking recipes + + Container container = makeDummyContainer(); + InventoryCrafting inventoryUnpack = new InventoryCrafting(container, 2, 2); + InventoryCrafting inventory2x2 = new InventoryCrafting(container, 2, 2); + InventoryCrafting inventory3x3 = new InventoryCrafting(container, 3, 3); + World world = null; // TODO: use a proper dummy world? + + List ret = new ArrayList(); + + for (IRecipe recipeUnpack : unpackingRecipes) { + ItemStack unpacked = recipeUnpack.getRecipeOutput(); + InventoryCrafting inventory = null; + + for (Iterator it = packingRecipes.iterator(); it.hasNext(); ) { + PackingRecipe recipePack = it.next(); + + // check if the packing recipe accepts the unpacking recipe's output + + boolean matched = false; + + if (recipePack.possibleInputs != null) { // the recipe could be parsed, use its inputs directly since that's faster + // verify recipe size + + if (recipePack.inputCount != unpacked.stackSize) continue; + + // check if any of the input options matches the unpacked item stack + + for (ItemStack stack : recipePack.possibleInputs) { + if (areInputsIdentical(unpacked, stack)) { + matched = true; + break; + } + } + } else { // unknown IRecipe, check through the recipe conventionally + // verify recipe size for 3x3 to skip anything smaller quickly + + if (unpacked.stackSize == 9 && recipePack.recipe.getRecipeSize() < 9) continue; + + // initialize inventory late, but only once per unpack recipe + + if (inventory == null) { + if (unpacked.stackSize == 4) { + inventory = inventory2x2; + } else { + inventory = inventory3x3; + } + + for (int i = 0; i < unpacked.stackSize; i++) { + inventory.setInventorySlotContents(i, unpacked.copy()); + } + } + + // check if the packing recipe accepts the unpacked item stack + + matched = recipePack.recipe.matches(inventory, world); + } + + if (matched) { + // check if the unpacking recipe accepts the packing recipe's output + + ItemStack packOutput = recipePack.recipe.getRecipeOutput(); + inventoryUnpack.setInventorySlotContents(0, packOutput.copy()); + + if (recipeUnpack.matches(inventoryUnpack, world)) { + ret.add(recipePack.recipe); + AlchemicalWizardry.logger.info("Adding the following recipe to the Compression Handler: " + packOutput); + it.remove(); + } + } + } + } + + return ret; } @SuppressWarnings("unchecked") @@ -55,8 +132,8 @@ public class StorageBlockCraftingRecipeAssimilator }; } - private boolean isPossiblePackingRecipe(IRecipe recipe) { - if (recipe.getRecipeSize() < 4) return false; + private PackingRecipe getPackingRecipe(IRecipe recipe) { + if (recipe.getRecipeSize() < 4) return null; List inputs; @@ -69,14 +146,35 @@ public class StorageBlockCraftingRecipeAssimilator } else if (recipe instanceof ShapelessOreRecipe) { inputs = ((ShapelessOreRecipe) recipe).getInput(); } else { - return true; + return new PackingRecipe(recipe, null, -1); } - return areInputsIdentical(inputs); + // check if the recipe inputs are size 4 or 9 + + int count = 0; + + for (Object o : inputs) { + if (o != null) count++; + } + + if (count != 4 && count != 9) return null; + + // grab identical inputs + + List identicalInputs = getIdenticalInputs(inputs); + if (identicalInputs == null) return null; + + return new PackingRecipe(recipe, identicalInputs, count); } + /** + * Determine the item stacks from the provided inputs which are suitable for every input element. + * + * @param inputs List of all inputs, null elements are being ignored. + * @return List List of all options. + */ @SuppressWarnings("unchecked") - private boolean areInputsIdentical(List inputs) { + private List getIdenticalInputs(List inputs) { List options = null; for (Object input : inputs) { @@ -89,7 +187,7 @@ public class StorageBlockCraftingRecipeAssimilator } else if (input instanceof List) { offers = (List) input; - if (offers.isEmpty()) return false; + if (offers.isEmpty()) return null; } else { throw new RuntimeException("invalid input: "+input.getClass()); } @@ -113,12 +211,12 @@ public class StorageBlockCraftingRecipeAssimilator if (!found) { it.remove(); - if (options.isEmpty()) return false; + if (options.isEmpty()) return null; } } } - return true; + return options; } private boolean areInputsIdentical(ItemStack a, ItemStack b) { @@ -129,4 +227,16 @@ public class StorageBlockCraftingRecipeAssimilator return dmgA == dmgB || dmgA == OreDictionary.WILDCARD_VALUE || dmgB == OreDictionary.WILDCARD_VALUE; } + + private static class PackingRecipe { + PackingRecipe(IRecipe recipe, List possibleInputs, int inputCount) { + this.recipe = recipe; + this.possibleInputs = possibleInputs; + this.inputCount = inputCount; + } + + final IRecipe recipe; + final List possibleInputs; + final int inputCount; + } } \ No newline at end of file diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/items/BoundAxe.java b/src/main/java/WayofTime/alchemicalWizardry/common/items/BoundAxe.java index 4444c00c..c4077953 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/items/BoundAxe.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/items/BoundAxe.java @@ -106,7 +106,7 @@ public class BoundAxe extends ItemAxe implements IBindable @Override public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { - if (EnergyItems.checkAndSetItemOwner(par1ItemStack, par3EntityPlayer) || par3EntityPlayer.isSneaking()) + if (!EnergyItems.checkAndSetItemOwner(par1ItemStack, par3EntityPlayer) || par3EntityPlayer.isSneaking()) { this.setActivated(par1ItemStack, !getActivated(par1ItemStack)); par1ItemStack.getTagCompound().setInteger("worldTimeDelay", (int) (par2World.getWorldTime() - 1) % 200); diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/items/sigil/ItemBloodLightSigil.java b/src/main/java/WayofTime/alchemicalWizardry/common/items/sigil/ItemBloodLightSigil.java index 1d672af8..514f5a1e 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/items/sigil/ItemBloodLightSigil.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/items/sigil/ItemBloodLightSigil.java @@ -49,6 +49,7 @@ public class ItemBloodLightSigil extends EnergyItems implements IHolding @Override public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) { + System.out.println("Being called"); if(!EnergyItems.checkAndSetItemOwner(par1ItemStack, par2EntityPlayer) || !EnergyItems.syphonBatteries(par1ItemStack, par2EntityPlayer, getEnergyUsed())) { return true; diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/items/sigil/ItemHarvestSigil.java b/src/main/java/WayofTime/alchemicalWizardry/common/items/sigil/ItemHarvestSigil.java index bd969f74..4016154b 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/items/sigil/ItemHarvestSigil.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/items/sigil/ItemHarvestSigil.java @@ -185,6 +185,10 @@ public class ItemHarvestSigil extends EnergyItems implements IHolding, ArmourUpg @Override public void onArmourUpdate(World world, EntityPlayer player, ItemStack thisItemStack) { + if(world.isRemote) + { + return; + } int range = 3; int verticalRange = 1; int posX = (int) Math.round(player.posX - 0.5f); diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/items/sigil/ItemPackRatSigil.java b/src/main/java/WayofTime/alchemicalWizardry/common/items/sigil/ItemPackRatSigil.java index 91ee478c..73f70290 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/items/sigil/ItemPackRatSigil.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/items/sigil/ItemPackRatSigil.java @@ -171,6 +171,10 @@ public class ItemPackRatSigil extends EnergyItems implements IHolding, ArmourUpg @Override public void onArmourUpdate(World world, EntityPlayer player, ItemStack thisItemStack) { + if(world.isRemote) + { + return; + } ItemStack stack = CompressionRegistry.compressInventory(player.inventory.mainInventory, world); if(stack != null) { diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/items/sigil/SigilOfHolding.java b/src/main/java/WayofTime/alchemicalWizardry/common/items/sigil/SigilOfHolding.java index 0294bcd5..96e4e8e5 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/items/sigil/SigilOfHolding.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/items/sigil/SigilOfHolding.java @@ -95,11 +95,37 @@ public class SigilOfHolding extends EnergyItems } } } + + @Override + public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) + { + if (checkAndSetItemOwner(par1ItemStack, par2EntityPlayer)) + { + int currentSlot = this.getSelectedSlot(par1ItemStack); + ItemStack[] inv = getInternalInventory(par1ItemStack); + + if (inv == null) + { + return false; + } + + ItemStack itemUsed = inv[currentSlot]; + + if (itemUsed == null) + { + return false; + } + + itemUsed.getItem().onItemUse(par1ItemStack, par2EntityPlayer, par3World, par4, par5, par6, par7, par8, par9, par10); + saveInternalInventory(par1ItemStack, inv); + } + + return true; + } @Override public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { - //TODO Might be a good idea to have this item need to be in the player's first slot if (checkAndSetItemOwner(par1ItemStack, par3EntityPlayer)) { if (par3EntityPlayer.isSneaking())