Big improvements on the compression handler.

This commit is contained in:
WayofTime 2015-03-02 20:51:24 -05:00
parent a2a25626d4
commit ff3e2685ff
3 changed files with 120 additions and 30 deletions

View file

@ -1,5 +1,5 @@
#
#Fri Feb 27 17:40:41 EST 2015
#Mon Mar 02 18:09: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=3
mc_version=1.7.10
build_number=6

View file

@ -1,6 +1,6 @@
package WayofTime.alchemicalWizardry.common.compress;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
@ -10,14 +10,17 @@ 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;
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
{
private static final StorageBlockCraftingManager instance = new StorageBlockCraftingManager();
private List recipes = new ArrayList();
private List recipes = new LinkedList();
public static StorageBlockCraftingManager getInstance()
{
@ -27,9 +30,75 @@ public class StorageBlockCraftingManager
public void addStorageBlockRecipes()
{
List list = CraftingManager.getInstance().getRecipeList();
List<IRecipe> tempRecipeList = new LinkedList();
World world = DimensionManager.getWorld(0);
for(Object obj : list)
for(Object obj : list)
{
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;
}
}
}
for(Object obj : tempRecipeList)
{
if(obj instanceof IRecipe)
{
@ -40,15 +109,16 @@ public class StorageBlockCraftingManager
continue;
}
if(isResultStackReversible(outputStack, 2, world) || isResultStackReversible(outputStack, 3, world))
if(isResultStackReversible(outputStack, 2, world, tempRecipeList) || isResultStackReversible(outputStack, 3, world, tempRecipeList))
{
recipes.add(recipe);
AlchemicalWizardry.logger.info("Now adding recipe for " + outputStack + " to the compression handler.");
}
}
}
}
public static boolean isResultStackReversible(ItemStack stack, int gridSize, World world)
public static boolean isResultStackReversible(ItemStack stack, int gridSize, World world, List list)
{
if(stack == null)
{
@ -64,8 +134,8 @@ public class StorageBlockCraftingManager
inventory.setInventorySlotContents(0, stack);
ItemStack returnStack = CraftingManager.getInstance().findMatchingRecipe(inventory, world);
if(returnStack == null)
ItemStack returnStack = StorageBlockCraftingManager.getInstance().findMatchingRecipe(inventory, world, list);
if(returnStack == null || returnStack.getItem() == null)
{
return false;
}
@ -74,10 +144,10 @@ public class StorageBlockCraftingManager
switch(gridSize)
{
case 2:
compressedStack = get22Recipe(returnStack, world);
compressedStack = get22Recipe(returnStack, world, list);
break;
case 3:
compressedStack = get33Recipe(returnStack, world);
compressedStack = get33Recipe(returnStack, world, list);
break;
}
@ -90,7 +160,7 @@ public class StorageBlockCraftingManager
}
}
public static ItemStack getRecipe(ItemStack stack, World world, int gridSize)
public static ItemStack getRecipe(ItemStack stack, World world, int gridSize, List list)
{
InventoryCrafting inventory = new InventoryCrafting(new Container()
{
@ -104,30 +174,35 @@ public class StorageBlockCraftingManager
inventory.setInventorySlotContents(i, stack);
}
return CraftingManager.getInstance().findMatchingRecipe(inventory, world);
return StorageBlockCraftingManager.getInstance().findMatchingRecipe(inventory, world, list);
}
public static boolean has22Recipe(ItemStack stack, World world)
public static boolean has22Recipe(ItemStack stack, World world, List list)
{
return get22Recipe(stack, world) != null;
return get22Recipe(stack, world, list) != null;
}
public static ItemStack get22Recipe(ItemStack stack, World world)
public static ItemStack get22Recipe(ItemStack stack, World world, List list)
{
return getRecipe(stack, world, 2);
return getRecipe(stack, world, 2, list);
}
public static boolean has33Recipe(ItemStack stack, World world)
public static boolean has33Recipe(ItemStack stack, World world, List list)
{
return get33Recipe(stack, world) != null;
return get33Recipe(stack, world, list) != null;
}
public static ItemStack get33Recipe(ItemStack stack, World world)
public static ItemStack get33Recipe(ItemStack stack, World world, List list)
{
return getRecipe(stack, world, 3);
return getRecipe(stack, world, 3, list);
}
public ItemStack findMatchingRecipe(InventoryCrafting p_82787_1_, World p_82787_2_)
{
return this.findMatchingRecipe(p_82787_1_, p_82787_2_, this.recipes);
}
public ItemStack findMatchingRecipe(InventoryCrafting p_82787_1_, World p_82787_2_, List list)
{
int i = 0;
ItemStack itemstack = null;
@ -171,9 +246,9 @@ public class StorageBlockCraftingManager
}
else
{
for (j = 0; j < this.recipes.size(); ++j)
for (j = 0; j < list.size(); ++j)
{
IRecipe irecipe = (IRecipe)this.recipes.get(j);
IRecipe irecipe = (IRecipe)list.get(j);
if (irecipe.matches(p_82787_1_, p_82787_2_))
{

View file

@ -1,22 +1,37 @@
package WayofTime.alchemicalWizardry.common.routing;
import WayofTime.alchemicalWizardry.api.RoutingFocusLogic;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
import WayofTime.alchemicalWizardry.api.RoutingFocusLogic;
import cpw.mods.fml.common.registry.GameData;
public class RoutingFocusLogicModItems extends RoutingFocusLogic
{
@Override
public boolean getDefaultMatch(ItemStack keyStack, ItemStack checkedStack)
{
if(keyStack != null && checkedStack != null)
if(keyStack != null && checkedStack != null && keyStack.getItem() != null && checkedStack.getItem() != null)
{
UniqueIdentifier keyId = GameRegistry.findUniqueIdentifierFor(keyStack.getItem());
UniqueIdentifier checkedId = GameRegistry.findUniqueIdentifierFor(checkedStack.getItem());
return keyId.modId.equals(checkedId.modId);
String keyId = getModID(keyStack.getItem());
String checkedId = getModID(checkedStack.getItem());
return keyId.equals(checkedId);
}
return false;
}
public String getModID(Item itm)
{
String str = GameData.getItemRegistry().getNameForObject(itm);
if(!str.isEmpty())
{
String[] strs = str.split(":");
if(strs != null && strs.length >= 1)
{
return strs[0];
}
}
return "";
}
}