Recipe Handler Lite™ is mostly done

This commit is contained in:
Alex_hawks 2013-12-31 16:48:46 +08:00
parent 662837fb3d
commit 4188288032
2 changed files with 138 additions and 0 deletions

View file

@ -0,0 +1,54 @@
package resonantinduction.api;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import resonantinduction.api.RecipeUtils.Resource;
public final class MachineRecipes
{
public static enum RecipeType
{
CRUSHER,
SAWMILL,
SMELTER,
FURNACE,
ROLLER,
BLAST_FURNACE,
METAL_FORMER;
}
private final Map<RecipeType, Map<List<Resource>, List<Resource>>> recipes = new HashMap<RecipeType, Map<List<Resource>, List<Resource>>>();
public static final MachineRecipes INSTANCE = new MachineRecipes();
private MachineRecipes()
{
for (RecipeType machine : RecipeType.values())
{
this.recipes.put(machine, new HashMap<List<Resource>, List<Resource>>());
}
}
public void addRecipe(RecipeType machine, List<Resource> input, List<Resource> output)
{
this.recipes.get(machine).put(input, output);
}
public void removeRecipe(RecipeType machine, List<Resource> input)
{
this.recipes.get(machine).remove(input);
}
public Map<List<Resource>, List<Resource>> getRecipes(RecipeType machine)
{
return new HashMap<List<Resource>, List<Resource>>(this.recipes.get(machine));
}
public Map<RecipeType, Map<List<Resource>, List<Resource>>> getRecipes()
{
return new HashMap<RecipeType, Map<List<Resource>, List<Resource>>>(this.recipes);
}
}

View file

@ -0,0 +1,84 @@
package resonantinduction.api;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
public class RecipeUtils
{
public static abstract class Resource
{
public final boolean hasChance;
public final float chance;
protected Resource()
{
this.hasChance = false;
this.chance = 100;
}
protected Resource(float chance)
{
this.hasChance = true;
this.chance = chance;
}
public abstract boolean isEqual(ItemStack is);
public boolean hasChance()
{
return this.hasChance;
}
public float getChance()
{
return this.chance;
}
}
public static class ItemStackResource extends Resource
{
public final ItemStack itemStack;
public ItemStackResource(ItemStack is)
{
super();
this.itemStack = is;
}
public ItemStackResource(ItemStack is, float chance)
{
super(chance);
this.itemStack = is;
}
@Override
public boolean isEqual(ItemStack is)
{
return is.equals(this.itemStack);
}
}
public static class OreDictResource extends Resource
{
public final String name;
public OreDictResource(String s)
{
super();
this.name = s;
}
public OreDictResource(String s, float chance)
{
super(chance);
this.name = s;
}
@Override
public boolean isEqual(ItemStack is)
{
return OreDictionary.getOres(this.name).contains(is);
}
}
}