mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-19 19:59:58 +00:00
130 lines
3.3 KiB
Java
130 lines
3.3 KiB
Java
package crazypants.enderio.machine.recipe;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraftforge.fluids.FluidStack;
|
|
|
|
import crazypants.enderio.machine.MachineRecipeInput;
|
|
import crazypants.util.EE3Util;
|
|
|
|
public class BasicManyToOneRecipe implements IManyToOneRecipe {
|
|
|
|
private final int energyRequired;
|
|
private final ItemStack output;
|
|
|
|
private final RecipeBonusType bonusType;
|
|
|
|
private final Recipe recipe;
|
|
|
|
public BasicManyToOneRecipe(Recipe recipe) {
|
|
this.recipe = recipe;
|
|
this.output = recipe.getOutputs()[0].getOutput().copy();
|
|
energyRequired = recipe.getEnergyRequired();
|
|
bonusType = recipe.getBonusType();
|
|
EE3Util.registerBasicToManyRecipe(recipe);
|
|
}
|
|
|
|
@Override
|
|
public boolean isValidRecipeComponents(ItemStack... items) {
|
|
|
|
List<RecipeInput> inputs = new ArrayList<RecipeInput>(Arrays.asList(recipe.getInputs()));
|
|
for (int slot = 0; slot < items.length; slot++) {
|
|
ItemStack is = items[slot];
|
|
if (is != null) {
|
|
RecipeInput remove = null;
|
|
for (RecipeInput ri : inputs) {
|
|
int riSlot = ri.getSlotNumber();
|
|
// Match by item type and, if the recipe specifies a slot, also by slot index
|
|
if (ri.isInput(is) && (riSlot == -1 || riSlot == slot)) {
|
|
remove = ri;
|
|
break;
|
|
}
|
|
}
|
|
if (remove != null) {
|
|
inputs.remove(remove);
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getOutput() {
|
|
return output;
|
|
}
|
|
|
|
@Override
|
|
public boolean isValidInput(int slot, ItemStack input) {
|
|
if (input == null) {
|
|
return false;
|
|
}
|
|
return getRecipeComponentFromInput(input) != null;
|
|
}
|
|
|
|
@Override
|
|
public boolean isValidInput(FluidStack fluid) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean isValid() {
|
|
return recipe != null && recipe.isValid();
|
|
}
|
|
|
|
@Override
|
|
public int getEnergyRequired() {
|
|
return energyRequired;
|
|
}
|
|
|
|
@Override
|
|
public RecipeBonusType getBonusType() {
|
|
return bonusType;
|
|
}
|
|
|
|
@Override
|
|
public RecipeOutput[] getOutputs() {
|
|
return recipe.getOutputs();
|
|
}
|
|
|
|
@Override
|
|
public List<ItemStack> getInputStacks() {
|
|
return recipe.getInputStacks();
|
|
}
|
|
|
|
@Override
|
|
public boolean isInputForRecipe(MachineRecipeInput... inputs) {
|
|
if (inputs == null) {
|
|
return false;
|
|
}
|
|
return recipe.isInputForRecipe(inputs);
|
|
}
|
|
|
|
@Override
|
|
public RecipeInput[] getInputs() {
|
|
return recipe.getInputs();
|
|
}
|
|
|
|
@Override
|
|
public List<FluidStack> getInputFluidStacks() {
|
|
return Collections.emptyList();
|
|
}
|
|
|
|
private ItemStack getRecipeComponentFromInput(ItemStack input) {
|
|
if (input == null) {
|
|
return null;
|
|
}
|
|
for (RecipeInput ri : recipe.getInputs()) {
|
|
if (ri.isInput(input)) {
|
|
return ri.getInput();
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|