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 @Override
public void postInit() public void postInit()
{ {
ItemDust.computeColors();
} }
@Override @Override

View file

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

View file

@ -1,24 +1,18 @@
package resonantinduction.api; package resonantinduction.api;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import resonantinduction.api.RecipeUtils.ItemStackResource;
import resonantinduction.api.RecipeUtils.*; import resonantinduction.api.RecipeUtils.OreDictResource;
import resonantinduction.api.RecipeUtils.Resource;
public final class MachineRecipes public final class MachineRecipes
{ {
public static enum RecipeType public static enum RecipeType
{ {
GRINDER, GRINDER, SAWMILL, SMELTER, FURNACE, ROLLER, BLAST_FURNACE, METAL_FORMER;
SAWMILL,
SMELTER,
FURNACE,
ROLLER,
BLAST_FURNACE,
METAL_FORMER;
} }
private final Map<RecipeType, Map<Resource[], Resource[]>> recipes = new HashMap<RecipeType, Map<Resource[], Resource[]>>(); 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); 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) public void removeRecipe(RecipeType machine, Resource[] input)
{ {
this.recipes.get(machine).remove(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)); 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); 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]; return this.getRecipes(machine).get(inputs);
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);
} }
} }

View file

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

View file

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

View file

@ -59,7 +59,7 @@ public class TileGrinderWheel extends TileElectrical
} }
public boolean canGrind(ItemStack itemStack) 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; return MachineRecipes.INSTANCE.getRecipe(RecipeType.GRINDER, itemStack) == null ? false : MachineRecipes.INSTANCE.getRecipe(RecipeType.GRINDER, itemStack).length > 0;
} }