GT5-Unofficial/src/main/java/gregtech/common/GT_IC2RecipesHandler.java

54 lines
1.7 KiB
Java
Raw Normal View History

package gregtech.common;
import ic2.api.recipe.IMachineRecipeManager;
import ic2.api.recipe.IRecipeInput;
import ic2.api.recipe.RecipeOutput;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import java.util.ArrayList;
public class GT_IC2RecipesHandler implements IMachineRecipeManager {
2016-09-12 11:07:17 +00:00
private ArrayList<RecipeIoContainer> recipes = new ArrayList<>();
@Override
public boolean addRecipe(IRecipeInput iRecipeInput, NBTTagCompound metadata, boolean replace, ItemStack... itemStacks) {
RecipeIoContainer ioContainer = new RecipeIoContainer(iRecipeInput, new RecipeOutput(metadata, itemStacks));
2016-09-12 11:07:17 +00:00
recipes.add(ioContainer);
return true;
}
@Override
public RecipeOutput getOutputFor(ItemStack input, boolean adjustInput) {
2016-09-12 11:07:17 +00:00
for(RecipeIoContainer ioContainer : recipes) {
if (ioContainer.input.matches(input)) {
if (adjustInput) {
if (input.getItem().hasContainerItem(input)) {
ItemStack container = input.getItem().getContainerItem(input);
input.setItem(container.getItem());
input.stackSize = container.stackSize;
input.setItemDamage(container.getItemDamage());
input.setTagCompound(container.getTagCompound());
} else {
input.stackSize -= ioContainer.input.getAmount();
}
}
2016-09-12 11:07:17 +00:00
return ioContainer.output;
}
}
2016-09-12 11:07:17 +00:00
return null;
}
@Override
public Iterable<RecipeIoContainer> getRecipes() {
2016-09-12 11:07:17 +00:00
return recipes;
}
@Override
public boolean isIterable() {
return true;
}
}