2013-08-27 00:49:32 +02:00
|
|
|
package mekanism.client.nei;
|
2013-08-10 21:52:59 +02:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.List;
|
|
|
|
|
2013-08-27 00:49:32 +02:00
|
|
|
import mekanism.api.energy.IEnergizedItem;
|
2013-08-10 21:52:59 +02:00
|
|
|
import mekanism.common.IEnergyCube;
|
|
|
|
import mekanism.common.IFactory;
|
2013-11-27 22:17:10 +01:00
|
|
|
import mekanism.common.block.BlockMachine.MachineType;
|
2014-01-08 02:55:50 +01:00
|
|
|
import mekanism.common.recipe.MekanismRecipe;
|
2013-08-10 21:52:59 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.item.crafting.CraftingManager;
|
|
|
|
import net.minecraft.item.crafting.IRecipe;
|
|
|
|
import codechicken.nei.PositionedStack;
|
|
|
|
import codechicken.nei.recipe.ShapedRecipeHandler;
|
|
|
|
|
|
|
|
public class MekanismRecipeHandler extends ShapedRecipeHandler
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public String getRecipeName()
|
|
|
|
{
|
|
|
|
return "Shaped Mekanism Crafting";
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-08-10 21:52:59 +02:00
|
|
|
@Override
|
|
|
|
public void loadCraftingRecipes(String outputId, Object... results)
|
|
|
|
{
|
|
|
|
if(outputId.equals("crafting") && getClass() == MekanismRecipeHandler.class)
|
|
|
|
{
|
|
|
|
List<IRecipe> allrecipes = CraftingManager.getInstance().getRecipeList();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-08-10 21:52:59 +02:00
|
|
|
for(IRecipe irecipe : allrecipes)
|
|
|
|
{
|
|
|
|
if(irecipe instanceof MekanismRecipe)
|
|
|
|
{
|
|
|
|
MekanismRecipe energyRecipe = (MekanismRecipe)irecipe;
|
|
|
|
CachedEnergyRecipe recipe = new CachedEnergyRecipe(energyRecipe.width, energyRecipe.height, energyRecipe.getInput(), energyRecipe.getRecipeOutput());
|
|
|
|
arecipes.add(recipe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
super.loadCraftingRecipes(outputId, results);
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-08-10 21:52:59 +02:00
|
|
|
@Override
|
|
|
|
public void loadCraftingRecipes(ItemStack result)
|
|
|
|
{
|
|
|
|
List<IRecipe> allrecipes = CraftingManager.getInstance().getRecipeList();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-08-10 21:52:59 +02:00
|
|
|
for(IRecipe irecipe : allrecipes)
|
|
|
|
{
|
|
|
|
if(irecipe instanceof MekanismRecipe && areItemsEqual(irecipe.getRecipeOutput(), result))
|
|
|
|
{
|
|
|
|
MekanismRecipe energyRecipe = (MekanismRecipe)irecipe;
|
|
|
|
CachedEnergyRecipe recipe = new CachedEnergyRecipe(energyRecipe.width, energyRecipe.height, energyRecipe.getInput(), energyRecipe.getRecipeOutput());
|
|
|
|
arecipes.add(recipe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-08-10 21:52:59 +02:00
|
|
|
@Override
|
|
|
|
public void loadUsageRecipes(ItemStack ingredient)
|
|
|
|
{
|
|
|
|
List<IRecipe> allrecipes = CraftingManager.getInstance().getRecipeList();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-08-10 21:52:59 +02:00
|
|
|
for(IRecipe irecipe : allrecipes)
|
|
|
|
{
|
|
|
|
if(irecipe instanceof MekanismRecipe)
|
|
|
|
{
|
|
|
|
MekanismRecipe energyRecipe = (MekanismRecipe)irecipe;
|
|
|
|
CachedEnergyRecipe recipe = new CachedEnergyRecipe(energyRecipe.width, energyRecipe.height, energyRecipe.getInput(), energyRecipe.getRecipeOutput());
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-08-10 21:52:59 +02:00
|
|
|
if(recipe.contains(recipe.ingredients, ingredient))
|
|
|
|
{
|
|
|
|
recipe.setIngredientPermutation(recipe.ingredients, ingredient);
|
|
|
|
arecipes.add(recipe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
|
|
|
public static boolean areItemsEqual(ItemStack stack1, ItemStack stack2)
|
|
|
|
{
|
|
|
|
if(stack1 == null && stack2 != null || stack1 != null && stack2 == null)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if(stack1 == null && stack2 == null)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(stack1.itemID != stack2.itemID)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!(stack1.getItem() instanceof IEnergizedItem) && !(stack2.getItem() instanceof IEnergizedItem))
|
|
|
|
{
|
|
|
|
if(stack1.getItemDamage() != stack2.getItemDamage())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(((IEnergizedItem)stack1.getItem()).isMetadataSpecific() && ((IEnergizedItem)stack2.getItem()).isMetadataSpecific())
|
|
|
|
{
|
|
|
|
if(stack1.getItemDamage() != stack2.getItemDamage())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(stack1.getItem() instanceof IEnergyCube && stack2.getItem() instanceof IEnergyCube)
|
|
|
|
{
|
|
|
|
if(((IEnergyCube)stack1.getItem()).getEnergyCubeTier(stack1) != ((IEnergyCube)stack2.getItem()).getEnergyCubeTier(stack2))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(stack1.getItem() instanceof IFactory && stack2.getItem() instanceof IFactory)
|
|
|
|
{
|
|
|
|
if(isFactory(stack1) && isFactory(stack2))
|
|
|
|
{
|
|
|
|
if(((IFactory)stack1.getItem()).getRecipeType(stack1) != ((IFactory)stack2.getItem()).getRecipeType(stack2))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean isFactory(ItemStack stack)
|
|
|
|
{
|
|
|
|
return MachineType.get(stack) == MachineType.BASIC_FACTORY || MachineType.get(stack) == MachineType.ADVANCED_FACTORY || MachineType.get(stack) == MachineType.ELITE_FACTORY;
|
|
|
|
}
|
|
|
|
|
2013-08-10 21:52:59 +02:00
|
|
|
public class CachedEnergyRecipe extends CachedRecipe
|
|
|
|
{
|
|
|
|
public ArrayList<PositionedStack> ingredients;
|
|
|
|
public PositionedStack result;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-08-10 21:52:59 +02:00
|
|
|
public CachedEnergyRecipe(int width, int height, Object[] items, ItemStack out)
|
|
|
|
{
|
|
|
|
result = new PositionedStack(out, 119, 24);
|
|
|
|
ingredients = new ArrayList<PositionedStack>();
|
|
|
|
setIngredients(width, height, items);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-08-10 21:52:59 +02:00
|
|
|
public void setIngredients(int width, int height, Object[] items)
|
|
|
|
{
|
|
|
|
for(int x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
for(int y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
if(items[y*width+x] == null)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-08-10 21:52:59 +02:00
|
|
|
PositionedStack stack = new PositionedStack(items[y*width+x], 25+x*18, 6+y*18);
|
|
|
|
stack.setMaxSize(1);
|
|
|
|
ingredients.add(stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-08-10 21:52:59 +02:00
|
|
|
@Override
|
|
|
|
public ArrayList<PositionedStack> getIngredients()
|
|
|
|
{
|
|
|
|
return (ArrayList<PositionedStack>)getCycledIngredients(MekanismRecipeHandler.this.cycleticks / 20, ingredients);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-08-10 21:52:59 +02:00
|
|
|
@Override
|
|
|
|
public PositionedStack getResult()
|
|
|
|
{
|
|
|
|
return result;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-08-10 21:52:59 +02:00
|
|
|
@Override
|
|
|
|
public boolean contains(Collection<PositionedStack> ingredients, ItemStack ingredient)
|
|
|
|
{
|
|
|
|
for(PositionedStack stack : ingredients)
|
|
|
|
{
|
|
|
|
for(ItemStack item : stack.items)
|
|
|
|
{
|
|
|
|
if(areItemsEqual(item, ingredient))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-08-10 21:52:59 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|