added onCraft, and canCraft

This commit is contained in:
modmuss50 2015-05-16 19:40:39 +01:00
parent 9b654eb1de
commit fd2f5d193a
3 changed files with 39 additions and 5 deletions

View file

@ -1,6 +1,7 @@
package techreborn.api.recipe;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import java.util.ArrayList;
import java.util.List;
@ -53,4 +54,14 @@ public abstract class BaseRecipe implements IBaseRecipeType {
public int euPerTick() {
return euPerTick;
}
@Override
public boolean canCraft(TileEntity tile) {
return true;
}
@Override
public boolean onCraft(TileEntity tile) {
return true;
}
}

View file

@ -1,6 +1,7 @@
package techreborn.api.recipe;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import java.util.List;
@ -42,4 +43,18 @@ public interface IBaseRecipeType {
* @return the amount of eu to be used per tick.
*/
public int euPerTick();
/**
*
* @param tile the tile that is doing the crafting
* @return if true the recipe will craft, if false it will not
*/
public boolean canCraft(TileEntity tile);
/**
*
* @param tile the tile that is doing the crafting
* @return return true if fluid was taken and should craft
*/
public boolean onCraft(TileEntity tile);
}

View file

@ -88,10 +88,18 @@ public class RecipeCrafter {
public void updateEntity() {
if (currentRecipe == null) {
for (IBaseRecipeType recipe : RecipeHanderer.getRecipeClassFromName(recipeName)) {
if(hasAllInputs(recipe)){
currentRecipe = recipe;
parentTile.syncWithAll();
return;
if(recipe.canCraft(parentTile) && hasAllInputs(recipe)){
boolean canGiveInvAll = true;
for (int i = 0; i < recipe.getOutputs().size(); i++) {
if (!canFitStack(recipe.getOutputs().get(i), outputSlots[i])) {
canGiveInvAll = false;
}
}
if(canGiveInvAll){
currentRecipe = recipe;
parentTile.syncWithAll();
return;
}
}
}
} else {
@ -109,7 +117,7 @@ public class RecipeCrafter {
}
}
ArrayList<Integer> filledSlots = new ArrayList<Integer>();
if (canGiveInvAll) {
if (canGiveInvAll && currentRecipe.onCraft(parentTile)) {
for (int i = 0; i < currentRecipe.getOutputs().size(); i++) {
if (!filledSlots.contains(outputSlots[i])) {
fitStack(currentRecipe.getOutputs().get(i), outputSlots[i]);