Big lag reducer! Horray!
This commit is contained in:
parent
ff3e2685ff
commit
e21f6941ba
3 changed files with 150 additions and 16 deletions
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
#Mon Mar 02 18:09:06 EST 2015
|
#Tue Mar 03 18:39:06 EST 2015
|
||||||
mod_name=BloodMagic
|
mod_name=BloodMagic
|
||||||
forge_version=10.13.2.1232
|
forge_version=10.13.2.1232
|
||||||
ccc_version=1.0.4.29
|
ccc_version=1.0.4.29
|
||||||
|
@ -8,5 +8,5 @@ nei_version=1.0.3.64
|
||||||
package_group=com.wayoftime.bloodmagic
|
package_group=com.wayoftime.bloodmagic
|
||||||
mod_version=1.3.1
|
mod_version=1.3.1
|
||||||
minetweaker_version=Dev-1.7.10-3.0.9B
|
minetweaker_version=Dev-1.7.10-3.0.9B
|
||||||
|
build_number=7
|
||||||
mc_version=1.7.10
|
mc_version=1.7.10
|
||||||
build_number=6
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ import net.minecraft.inventory.Container;
|
||||||
import net.minecraft.inventory.InventoryCrafting;
|
import net.minecraft.inventory.InventoryCrafting;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.crafting.CraftingManager;
|
|
||||||
import net.minecraft.item.crafting.IRecipe;
|
import net.minecraft.item.crafting.IRecipe;
|
||||||
import net.minecraft.item.crafting.ShapedRecipes;
|
import net.minecraft.item.crafting.ShapedRecipes;
|
||||||
import net.minecraft.item.crafting.ShapelessRecipes;
|
import net.minecraft.item.crafting.ShapelessRecipes;
|
||||||
|
@ -29,12 +28,13 @@ public class StorageBlockCraftingManager
|
||||||
|
|
||||||
public void addStorageBlockRecipes()
|
public void addStorageBlockRecipes()
|
||||||
{
|
{
|
||||||
List list = CraftingManager.getInstance().getRecipeList();
|
this.recipes = new StorageBlockCraftingRecipeAssimilator().getPackingOptions();
|
||||||
|
|
||||||
List<IRecipe> tempRecipeList = new LinkedList();
|
List<IRecipe> tempRecipeList = new LinkedList();
|
||||||
|
|
||||||
World world = DimensionManager.getWorld(0);
|
World world = DimensionManager.getWorld(0);
|
||||||
|
|
||||||
for(Object obj : list)
|
for(Object obj : this.recipes)
|
||||||
{
|
{
|
||||||
if(obj instanceof IRecipe)
|
if(obj instanceof IRecipe)
|
||||||
{
|
{
|
||||||
|
@ -93,11 +93,11 @@ public class StorageBlockCraftingManager
|
||||||
tempRecipeList.add(recipe);
|
tempRecipeList.add(recipe);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<IRecipe> tempRecipeList2 = new LinkedList();
|
||||||
|
|
||||||
for(Object obj : tempRecipeList)
|
for(Object obj : tempRecipeList)
|
||||||
{
|
{
|
||||||
if(obj instanceof IRecipe)
|
if(obj instanceof IRecipe)
|
||||||
|
@ -111,14 +111,16 @@ public class StorageBlockCraftingManager
|
||||||
|
|
||||||
if(isResultStackReversible(outputStack, 2, world, tempRecipeList) || isResultStackReversible(outputStack, 3, world, tempRecipeList))
|
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.");
|
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)
|
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()
|
InventoryCrafting inventory = new InventoryCrafting(new Container()
|
||||||
{
|
{
|
||||||
|
@ -177,22 +179,22 @@ public class StorageBlockCraftingManager
|
||||||
return StorageBlockCraftingManager.getInstance().findMatchingRecipe(inventory, world, list);
|
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;
|
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);
|
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;
|
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);
|
return getRecipe(stack, world, 3, list);
|
||||||
}
|
}
|
||||||
|
@ -202,7 +204,7 @@ public class StorageBlockCraftingManager
|
||||||
return this.findMatchingRecipe(p_82787_1_, p_82787_2_, this.recipes);
|
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;
|
int i = 0;
|
||||||
ItemStack itemstack = null;
|
ItemStack itemstack = null;
|
||||||
|
|
|
@ -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<IRecipe> getPackingOptions()
|
||||||
|
{
|
||||||
|
List<IRecipe> packingRecipes = new ArrayList<IRecipe>();
|
||||||
|
List<IRecipe> unpackingRecipes = new ArrayList<IRecipe>();
|
||||||
|
|
||||||
|
List<IRecipe> 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<IRecipe> 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<ItemStack> options = null;
|
||||||
|
|
||||||
|
for (Object input : inputs) {
|
||||||
|
if (input == null) continue;
|
||||||
|
|
||||||
|
List<ItemStack> offers;
|
||||||
|
|
||||||
|
if (input instanceof ItemStack) {
|
||||||
|
offers = Arrays.asList((ItemStack) input);
|
||||||
|
} else if (input instanceof List) {
|
||||||
|
offers = (List<ItemStack>) input;
|
||||||
|
|
||||||
|
if (offers.isEmpty()) return false;
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("invalid input: "+input.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options == null) {
|
||||||
|
options = new ArrayList<ItemStack>(offers);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Iterator<ItemStack> 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue