Switched to use Java equals()

This commit is contained in:
Calclavia 2014-01-05 17:43:59 +08:00
parent 26a269a6b5
commit 7acfada35c
6 changed files with 168 additions and 184 deletions

View file

@ -50,7 +50,6 @@ public class ClientProxy extends CommonProxy
@Override
public void postInit()
{
ItemDust.computeColors();
}
@Override

View file

@ -326,7 +326,7 @@ public class ResonantInduction
}
/** Auto-gen dusts */
ItemDust.postInit();
ItemDust.generateDusts();
ResonantInduction.proxy.postInit();
/** Inject new furnace tile class */

View file

@ -1,24 +1,18 @@
package resonantinduction.api;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.item.ItemStack;
import resonantinduction.api.RecipeUtils.*;
import resonantinduction.api.RecipeUtils.ItemStackResource;
import resonantinduction.api.RecipeUtils.OreDictResource;
import resonantinduction.api.RecipeUtils.Resource;
public final class MachineRecipes
{
public static enum RecipeType
{
GRINDER,
SAWMILL,
SMELTER,
FURNACE,
ROLLER,
BLAST_FURNACE,
METAL_FORMER;
GRINDER, SAWMILL, SMELTER, FURNACE, ROLLER, BLAST_FURNACE, METAL_FORMER;
}
private final Map<RecipeType, Map<Resource[], Resource[]>> recipes = new HashMap<RecipeType, Map<Resource[], Resource[]>>();
@ -38,12 +32,22 @@ public final class MachineRecipes
this.recipes.get(machine).put(input, output);
}
public void addRecipe(RecipeType machine, ItemStack input, ItemStack output)
{
this.addRecipe(machine, new ItemStackResource[] { new ItemStackResource(input) }, new ItemStackResource[] { new ItemStackResource(output) });
}
public void addRecipe(RecipeType machine, String input, ItemStack output)
{
this.addRecipe(machine, new OreDictResource[] { new OreDictResource(input) }, new ItemStackResource[] { new ItemStackResource(output) });
}
public void removeRecipe(RecipeType machine, Resource[] input)
{
this.recipes.get(machine).remove(input);
}
public Map<Resource[], Resource[]>getRecipes(RecipeType machine)
public Map<Resource[], Resource[]> getRecipes(RecipeType machine)
{
return new HashMap<Resource[], Resource[]>(this.recipes.get(machine));
}
@ -53,16 +57,9 @@ public final class MachineRecipes
return new HashMap<RecipeType, Map<Resource[], Resource[]>>(this.recipes);
}
public Resource[] getRecipe(RecipeType machine, ItemStack primary, ItemStack... secondary)
public Resource[] getRecipe(RecipeType machine, ItemStack... inputs)
{
Resource[] input = new Resource[secondary.length +1];
input[0] = new ItemStackResource(primary);
for (int i = 0; i < secondary.length; i++)
{
input[i+1] = new ItemStackResource(secondary[i]);
}
return this.getRecipes(machine).get(input);
return this.getRecipes(machine).get(inputs);
}
}

View file

@ -23,9 +23,6 @@ public class RecipeUtils
this.chance = chance;
}
public abstract boolean isEqual(ItemStack is);
public abstract boolean isEqual(FluidStack fs);
public boolean hasChance()
{
return this.hasChance;
@ -54,15 +51,9 @@ public class RecipeUtils
}
@Override
public boolean isEqual(ItemStack is)
public boolean equals(Object obj)
{
return is.equals(this.itemStack);
}
@Override
public boolean isEqual(FluidStack fs)
{
return false;
return (obj instanceof ItemStack) ? ((ItemStack) obj).equals(this.itemStack) : false;
}
}
@ -83,15 +74,9 @@ public class RecipeUtils
}
@Override
public boolean isEqual(ItemStack is)
public boolean equals(Object obj)
{
return OreDictionary.getOres(this.name).contains(is);
}
@Override
public boolean isEqual(FluidStack fs)
{
return false;
return (obj instanceof ItemStack) ? OreDictionary.getOres(this.name).contains(((ItemStack) obj)) : false;
}
}
@ -112,15 +97,9 @@ public class RecipeUtils
}
@Override
public boolean isEqual(ItemStack is)
public boolean equals(Object obj)
{
return false;
}
@Override
public boolean isEqual(FluidStack fs)
{
return fs.isFluidEqual(this.fluidStack);
return (obj instanceof FluidStack) ? ((FluidStack) obj).equals(obj) : false;
}
}
}

View file

@ -24,6 +24,8 @@ import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.OreDictionary.OreRegisterEvent;
import resonantinduction.ResonantInduction;
import resonantinduction.api.MachineRecipes;
import resonantinduction.api.MachineRecipes.RecipeType;
import resonantinduction.api.OreDetectionBlackList;
import resonantinduction.core.base.ItemBase;
import calclavia.lib.Calclavia;
@ -40,7 +42,7 @@ import cpw.mods.fml.relauncher.SideOnly;
*/
public class ItemDust extends ItemBase
{
public static final Set<String> ingotNames = new HashSet<String>();
public static final Set<String> materialNames = new HashSet<String>();
public static final Set<ItemStack> dusts = new HashSet<ItemStack>();
public static final HashMap<String, Integer> ingotColors = new HashMap<String, Integer>();
@ -70,7 +72,7 @@ public class ItemDust extends ItemBase
if (OreDetectionBlackList.isIngotBlackListed("ingot" + ingotName) || OreDetectionBlackList.isOreBlackListed("ore" + ingotName))
return;
ingotNames.add(ingotName.toLowerCase());
materialNames.add(ingotName.toLowerCase());
}
}
@ -81,16 +83,23 @@ public class ItemDust extends ItemBase
computeColors();
}
public static void postInit()
public static void generateDusts()
{
for (String ingotName : ingotNames)
for (String materialName : materialNames)
{
String name = ingotName.substring(0, 1).toUpperCase() + ingotName.substring(1);
String name = materialName.substring(0, 1).toUpperCase() + materialName.substring(1);
if (OreDictionary.getOres("dust" + name).size() == 0 && OreDictionary.getOres("ore" + name).size() > 0)
if (OreDictionary.getOres("ore" + name).size() > 0)
{
dusts.add(getStackFromDust(ingotName));
OreDictionary.registerOre("dust" + name, getStackFromDust(ingotName));
if (OreDictionary.getOres("dust" + name).size() == 0)
{
dusts.add(getStackFromDust(materialName));
OreDictionary.registerOre("dust" + name, getStackFromDust(materialName));
}
// Add to machine recipes
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER, "ore" + name, OreDictionary.getOres("dust" + name).get(0));
}
}
}
@ -98,7 +107,7 @@ public class ItemDust extends ItemBase
@SideOnly(Side.CLIENT)
public static void computeColors()
{
for (String ingotName : ingotNames)
for (String ingotName : materialNames)
{
LinkedList<Integer> colorCodes = new LinkedList<Integer>();
@ -121,7 +130,7 @@ public class ItemDust extends ItemBase
}
catch (ReflectiveOperationException e1)
{
//e1.printStackTrace();
// e1.printStackTrace();
break;
}
@ -146,7 +155,7 @@ public class ItemDust extends ItemBase
}
catch (IOException e)
{
//e.printStackTrace();
// e.printStackTrace();
}
}
if (colorCodes.size() > 0)

View file

@ -59,7 +59,7 @@ public class TileGrinderWheel extends TileElectrical
}
public boolean canGrind(ItemStack itemStack)
{
{System.out.println(MachineRecipes.INSTANCE.getRecipe(RecipeType.GRINDER, itemStack));
return MachineRecipes.INSTANCE.getRecipe(RecipeType.GRINDER, itemStack) == null ? false : MachineRecipes.INSTANCE.getRecipe(RecipeType.GRINDER, itemStack).length > 0;
}