mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-22 04:52:25 +00:00
Reduced Formulaic Assemblicator CPU usage by a factor of 10
This commit is contained in:
1 parent
2873c0c797
commit
8f96e51142
3 files changed
+16
-28
No files matched your search
@@ -14,17 +14,22 @@ public class RecipeFormula
|
||||
|
||||
public ItemStack[] input = new ItemStack[9];
|
||||
|
||||
public RecipeFormula(ItemStack[] inv)
|
||||
public IRecipe recipe = null;
|
||||
|
||||
public RecipeFormula(World world, ItemStack[] inv)
|
||||
{
|
||||
this(inv, 0);
|
||||
this(world, inv, 0);
|
||||
}
|
||||
|
||||
public RecipeFormula(ItemStack[] inv, int start)
|
||||
public RecipeFormula(World world, ItemStack[] inv, int start)
|
||||
{
|
||||
for(int i = 0; i < 9; i++)
|
||||
{
|
||||
input[i] = StackUtils.size(inv[start+i], 1);
|
||||
}
|
||||
|
||||
resetToRecipe();
|
||||
recipe = RecipeUtils.getRecipeFromGrid(dummy, world);
|
||||
}
|
||||
|
||||
private void resetToRecipe()
|
||||
@@ -37,44 +42,29 @@ public class RecipeFormula
|
||||
|
||||
public boolean matches(World world, ItemStack[] newInput, int start)
|
||||
{
|
||||
resetToRecipe();
|
||||
|
||||
IRecipe origRecipe = RecipeUtils.getRecipeFromGrid(dummy, world);
|
||||
|
||||
for(int i = 0; i < 9; i++)
|
||||
{
|
||||
dummy.setInventorySlotContents(i, newInput[start+i]);
|
||||
}
|
||||
|
||||
IRecipe newRecipe = RecipeUtils.getRecipeFromGrid(dummy, world);
|
||||
|
||||
return origRecipe == newRecipe;
|
||||
return recipe.matches(dummy, world);
|
||||
}
|
||||
|
||||
public boolean isIngredientInPos(World world, ItemStack stack, int i)
|
||||
{
|
||||
resetToRecipe();
|
||||
|
||||
IRecipe origRecipe = RecipeUtils.getRecipeFromGrid(dummy, world);
|
||||
dummy.setInventorySlotContents(i, stack);
|
||||
IRecipe newRecipe = RecipeUtils.getRecipeFromGrid(dummy, world);
|
||||
|
||||
return origRecipe == newRecipe;
|
||||
return recipe.matches(dummy, world);
|
||||
}
|
||||
|
||||
public boolean isIngredient(World world, ItemStack stack)
|
||||
{
|
||||
resetToRecipe();
|
||||
|
||||
IRecipe origRecipe = RecipeUtils.getRecipeFromGrid(dummy, world);
|
||||
|
||||
for(int i = 0; i < 9; i++)
|
||||
{
|
||||
dummy.setInventorySlotContents(i, stack);
|
||||
|
||||
IRecipe newRecipe = RecipeUtils.getRecipeFromGrid(dummy, world);
|
||||
|
||||
if(origRecipe == newRecipe)
|
||||
if(recipe.matches(dummy, world))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -92,9 +82,7 @@ public class RecipeFormula
|
||||
|
||||
public IRecipe getRecipe(World world)
|
||||
{
|
||||
resetToRecipe();
|
||||
|
||||
return RecipeUtils.getRecipeFromGrid(dummy, world);
|
||||
return recipe;
|
||||
}
|
||||
|
||||
public boolean isFormulaEqual(World world, RecipeFormula formula)
|
||||
|
||||
@@ -108,7 +108,7 @@ public class TileEntityFormulaicAssemblicator extends TileEntityElectricBlock im
|
||||
|
||||
if(item.getInventory(inventory[2]) != null && !item.isInvalid(inventory[2]))
|
||||
{
|
||||
RecipeFormula itemFormula = new RecipeFormula(item.getInventory(inventory[2]));
|
||||
RecipeFormula itemFormula = new RecipeFormula(worldObj, item.getInventory(inventory[2]));
|
||||
|
||||
if(itemFormula.isValidFormula(worldObj))
|
||||
{
|
||||
@@ -144,7 +144,7 @@ public class TileEntityFormulaicAssemblicator extends TileEntityElectricBlock im
|
||||
{
|
||||
boolean canOperate = true;
|
||||
|
||||
if(!formula.matches(worldObj, inventory, 27))
|
||||
if(!isRecipe)
|
||||
{
|
||||
canOperate = moveItemsToGrid();
|
||||
}
|
||||
@@ -456,7 +456,7 @@ public class TileEntityFormulaicAssemblicator extends TileEntityElectricBlock im
|
||||
|
||||
if(item.getInventory(inventory[2]) == null)
|
||||
{
|
||||
RecipeFormula formula = new RecipeFormula(inventory, 27);
|
||||
RecipeFormula formula = new RecipeFormula(worldObj, inventory, 27);
|
||||
|
||||
if(formula.isValidFormula(worldObj))
|
||||
{
|
||||
@@ -592,7 +592,7 @@ public class TileEntityFormulaicAssemblicator extends TileEntityElectricBlock im
|
||||
}
|
||||
}
|
||||
|
||||
formula = new RecipeFormula(inv);
|
||||
formula = new RecipeFormula(worldObj, inv);
|
||||
}
|
||||
else {
|
||||
formula = null;
|
||||
|
||||
Reference in new issue
Block a user