Removed old crafting guff thats no longer needed.

This commit is contained in:
CrazyPants committed 2014-08-29 00:48:38 +08:00
1 parent ac3000efcc
commit 1743f8f94d
10 files changed
-540

No files matched your search

@@ -1,33 +0,0 @@
package crazypants.enderio.crafting;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import crazypants.enderio.ModObject;
public interface IEnderIoRecipe {
public static final String PAINTER_ID = ModObject.blockPainter.unlocalisedName;
public static final String ALLOY_SMELTER_ID = ModObject.blockAlloySmelter.unlocalisedName;
public static final String SAG_MILL_ID = ModObject.blockSagMill.unlocalisedName;
public static final String VAT_ID = ModObject.blockVat.unlocalisedName;
String getCrafterId();
List<IRecipeInput> getInputs();
List<IRecipeOutput> getOutputs();
boolean isInput(ItemStack input);
boolean isOutput(ItemStack output);
float getRequiredEnergy();
boolean isOutput(FluidStack fluid);
}
@@ -1,43 +0,0 @@
package crazypants.enderio.crafting;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
public abstract interface IRecipeComponent {
/**
* Returns a prototype of the ItemStack as required by the recipe. The
* returned stack must be a valid component of the recipe, but it may not
* reflect all possible valid values. For example, if a recipe input accepts
* multiple metadata or NBT values, this stack will only be one of the
* possible valid inputs. To test if a particular instance of an item stack
* may be used the isEquivalent method should be called.
*
* @return
*/
ItemStack getItem();
FluidStack getFluid();
/**
* Equivalent to getItem().stacksize
*
* @return
*/
int getQuantity();
/**
* Returns the slot this component must be placed in. If any slot can be used
* the method return -1.
*
* @return
*/
int getSlot();
boolean isValidSlot(int slot);
boolean isEquivalent(ItemStack candidate);
boolean isEquivalent(FluidStack output);
}
@@ -1,11 +0,0 @@
package crazypants.enderio.crafting;
import java.util.List;
import net.minecraft.item.ItemStack;
public interface IRecipeInput extends IRecipeComponent {
public List<ItemStack> getEquivelentInputs();
}
@@ -1,12 +0,0 @@
package crazypants.enderio.crafting;
public interface IRecipeOutput extends IRecipeComponent {
/**
* The '% chance' this output is generated. This value is in the range 0-1.
*
* @return
*/
float getChance();
}
@@ -1,84 +0,0 @@
package crazypants.enderio.crafting;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
public final class RecipeReigistry {
public static final RecipeReigistry instance = new RecipeReigistry();
private final Map<String, List<IEnderIoRecipe>> crafterRecipes = new HashMap<String, List<IEnderIoRecipe>>();
public void registerRecipe(IEnderIoRecipe recipe) {
List<IEnderIoRecipe> recipes = getRecipesForCrafter(recipe.getCrafterId());
recipes.add(recipe);
}
public void registerRecipes(List<IEnderIoRecipe> recipes) {
for (IEnderIoRecipe recipe : recipes) {
registerRecipe(recipe);
}
}
public List<IEnderIoRecipe> getRecipesForOutput(String crafterId, FluidStack fluid) {
return getRecipesForOutput(crafterId, fluid, null);
}
public List<IEnderIoRecipe> getRecipesForOutput(String crafterId, ItemStack output) {
return getRecipesForOutput(crafterId, output, null);
}
public List<IEnderIoRecipe> getRecipesForOutput(ItemStack output) {
ArrayList<IEnderIoRecipe> result = new ArrayList<IEnderIoRecipe>();
for (String crafter : crafterRecipes.keySet()) {
getRecipesForOutput(crafter, output, result);
}
return result;
}
public List<IEnderIoRecipe> getRecipesForOutput(String crafterId, ItemStack output, List<IEnderIoRecipe> result) {
if(result == null) {
result = new ArrayList<IEnderIoRecipe>();
}
List<IEnderIoRecipe> recipes = getRecipesForCrafter(crafterId);
for (IEnderIoRecipe recipe : recipes) {
if(recipe.isOutput(output)) {
result.add(recipe);
}
}
return result;
}
public List<IEnderIoRecipe> getRecipesForOutput(String crafterId, FluidStack fluid, List<IEnderIoRecipe> result) {
if(result == null) {
result = new ArrayList<IEnderIoRecipe>();
}
List<IEnderIoRecipe> recipes = getRecipesForCrafter(crafterId);
for (IEnderIoRecipe recipe : recipes) {
if(recipe.isOutput(fluid)) {
result.add(recipe);
}
}
return result;
}
public List<IEnderIoRecipe> getRecipesForCrafter(String crafterId) {
List<IEnderIoRecipe> result = crafterRecipes.get(crafterId);
if(result == null) {
result = new ArrayList<IEnderIoRecipe>();
crafterRecipes.put(crafterId, result);
}
return result;
}
private RecipeReigistry() {
}
}
@@ -1,125 +0,0 @@
package crazypants.enderio.crafting.impl;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import crazypants.enderio.crafting.IEnderIoRecipe;
import crazypants.enderio.crafting.IRecipeComponent;
import crazypants.enderio.crafting.IRecipeInput;
import crazypants.enderio.crafting.IRecipeOutput;
public class EnderIoRecipe implements IEnderIoRecipe {
private final String crafterId;
private final float requiredEnergy;
private final List<IRecipeInput> inputs = new ArrayList<IRecipeInput>();
private final List<IRecipeInput> inputsRO = Collections.unmodifiableList(inputs);
private final List<IRecipeOutput> outputs = new ArrayList<IRecipeOutput>();
private final List<IRecipeOutput> outputsRO = Collections.unmodifiableList(outputs);
public EnderIoRecipe(String crafterId, float requiredEnergy, ItemStack input, ItemStack output) {
this(crafterId, requiredEnergy);
inputs.add(new RecipeInput(input));
outputs.add(new RecipeOutput(output));
}
public EnderIoRecipe(String crafterId, float requiredEnergy, ItemStack input, IRecipeOutput... outputs) {
this(crafterId, requiredEnergy);
inputs.add(new RecipeInput(input));
for (IRecipeOutput output : outputs) {
this.outputs.add(output);
}
}
public EnderIoRecipe(String crafterId, float requiredEnergy, IRecipeComponent... components) {
this(crafterId, requiredEnergy);
for (IRecipeComponent component : components) {
if(component instanceof IRecipeOutput) {
outputs.add((IRecipeOutput) component);
} else if(component instanceof IRecipeInput) {
inputs.add((IRecipeInput) component);
}
}
}
public EnderIoRecipe(String crafterId, float requiredEnergy, Collection<IRecipeComponent> components) {
this(crafterId, requiredEnergy);
for (IRecipeComponent component : components) {
if(component instanceof IRecipeOutput) {
outputs.add((IRecipeOutput) component);
} else if(component instanceof IRecipeInput) {
inputs.add((IRecipeInput) component);
}
}
}
private EnderIoRecipe(String crafterId, float requiredEnergy) {
this.crafterId = crafterId;
this.requiredEnergy = requiredEnergy;
}
@Override
public String getCrafterId() {
return crafterId;
}
@Override
public List<IRecipeInput> getInputs() {
return inputsRO;
}
@Override
public List<IRecipeOutput> getOutputs() {
return outputsRO;
}
@Override
public boolean isInput(ItemStack input) {
for (IRecipeComponent rc : inputs) {
if(rc.isEquivalent(input)) {
return true;
}
}
return false;
}
@Override
public boolean isOutput(FluidStack output) {
if(output == null) {
return false;
}
for (IRecipeComponent rc : outputs) {
if(rc.isEquivalent(output)) {
return true;
}
}
return false;
}
@Override
public boolean isOutput(ItemStack output) {
if(output == null) {
return false;
}
for (IRecipeComponent rc : outputs) {
if(rc.isEquivalent(output)) {
return true;
}
}
return false;
}
@Override
public float getRequiredEnergy() {
return requiredEnergy;
}
}
@@ -1,74 +0,0 @@
package crazypants.enderio.crafting.impl;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import crazypants.enderio.crafting.IRecipeComponent;
public abstract class RecipeComponent implements IRecipeComponent {
protected final ItemStack itemPrototype;
protected final FluidStack fluidPrototype;
protected final int slot;
public RecipeComponent(ItemStack itemPrototype) {
this(itemPrototype, -1);
}
public RecipeComponent(ItemStack itemPrototype, int slot) {
this.itemPrototype = itemPrototype;
this.fluidPrototype = null;
this.slot = slot;
}
public RecipeComponent(FluidStack fluidProto, int slot) {
this.itemPrototype = null;
this.fluidPrototype = fluidProto;
this.slot = slot;
}
@Override
public FluidStack getFluid() {
if(fluidPrototype == null) {
return null;
}
return fluidPrototype.copy();
}
@Override
public ItemStack getItem() {
if(itemPrototype == null) {
return null;
}
return itemPrototype.copy();
}
@Override
public int getQuantity() {
return itemPrototype.stackSize;
}
@Override
public int getSlot() {
return slot;
}
@Override
public boolean isValidSlot(int slot) {
return this.slot < 0 || this.slot == slot;
}
protected boolean isEqual(ItemStack left, ItemStack right) {
if(left != null && left.isItemEqual(right)) {
return left.stackTagCompound == null ? true : right.stackTagCompound != null && left.stackTagCompound.equals(right.stackTagCompound);
}
return false;
}
@Override
public boolean isEquivalent(FluidStack output) {
return fluidPrototype != null && output != null && fluidPrototype.isFluidEqual(output);
}
}
@@ -1,72 +0,0 @@
package crazypants.enderio.crafting.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import crazypants.enderio.crafting.IRecipeInput;
public class RecipeInput extends RecipeComponent implements IRecipeInput {
private final List<ItemStack> equivelents;
public RecipeInput(ItemStack itemPrototype, int slot, ItemStack... equivs) {
super(itemPrototype, slot);
if(equivs == null) {
equivelents = Collections.emptyList();
} else {
equivelents = new ArrayList<ItemStack>(equivs.length);
for (ItemStack st : equivs) {
equivelents.add(st);
}
}
}
public RecipeInput(ItemStack input) {
this(input, input == null ? false : (input.getItem() == null ? false : input.getItemDamage() == 0));
}
public RecipeInput(ItemStack input, boolean addSubtypes) {
super(input, -1);
Item inputItem = input == null ? null : input.getItem();
if(addSubtypes && inputItem != null && inputItem.getHasSubtypes()) {
equivelents = new ArrayList<ItemStack>();
ArrayList<ItemStack> sublist = new ArrayList<ItemStack>();
inputItem.getSubItems(inputItem, null, sublist);
for (ItemStack st : sublist) {
if(itemPrototype.getItemDamage() != st.getItemDamage()) {
equivelents.add(st.copy());
}
}
} else {
equivelents = Collections.emptyList();
}
}
public RecipeInput(FluidStack fluidInput, int slot) {
super(fluidInput, slot);
equivelents = Collections.emptyList();
}
@Override
public boolean isEquivalent(ItemStack candidate) {
if(isEqual(itemPrototype, candidate)) {
return true;
}
for (ItemStack stack : equivelents) {
if(isEqual(stack, candidate)) {
return true;
}
}
return false;
}
@Override
public List<ItemStack> getEquivelentInputs() {
return equivelents;
}
}
@@ -1,43 +0,0 @@
package crazypants.enderio.crafting.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import crazypants.enderio.crafting.IRecipeInput;
import crazypants.util.Util;
public class RecipeInputClass<T> extends RecipeComponent implements IRecipeInput {
private final List<ItemStack> equivelents;
private final Class<T> allowedClass;
public RecipeInputClass(ItemStack protoType, Class<T> allowedClass, ItemStack... knownSubtypes) {
super(protoType, -1);
this.allowedClass = allowedClass;
if(knownSubtypes == null) {
equivelents = Collections.emptyList();
} else {
equivelents = new ArrayList<ItemStack>();
for (ItemStack subT : knownSubtypes) {
equivelents.add(subT);
}
}
}
@Override
public boolean isEquivalent(ItemStack candidate) {
Block block = Util.getBlockFromItemId(candidate);
Item item = candidate.getItem();
return (item != null && allowedClass.isAssignableFrom(item.getClass()) || (block != null && allowedClass.isAssignableFrom(block.getClass())));
}
@Override
public List<ItemStack> getEquivelentInputs() {
return equivelents;
}
}
@@ -1,43 +0,0 @@
package crazypants.enderio.crafting.impl;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import crazypants.enderio.crafting.IRecipeOutput;
public class RecipeOutput extends RecipeComponent implements IRecipeOutput {
protected final float chance;
public RecipeOutput(ItemStack itemPrototype) {
this(itemPrototype, -1);
}
public RecipeOutput(ItemStack itemPrototype, int slot) {
this(itemPrototype, slot, 1);
}
public RecipeOutput(ItemStack itemPrototype, float chance) {
this(itemPrototype, -1, chance);
}
public RecipeOutput(ItemStack itemPrototype, int slot, float chance) {
super(itemPrototype, slot);
this.chance = chance;
}
public RecipeOutput(FluidStack fluidOutput, int slot) {
super(fluidOutput, slot);
chance = 1.0f;
}
@Override
public float getChance() {
return chance;
}
@Override
public boolean isEquivalent(ItemStack candidate) {
return isEqual(itemPrototype, candidate);
}
}