2015-11-01 17:24:35 +01:00
|
|
|
package techreborn.compat.minetweaker;
|
|
|
|
|
|
|
|
import minetweaker.IUndoableAction;
|
|
|
|
import minetweaker.MineTweakerAPI;
|
|
|
|
import minetweaker.api.item.IIngredient;
|
|
|
|
import minetweaker.api.item.IItemStack;
|
2015-11-12 09:22:39 +01:00
|
|
|
import minetweaker.api.minecraft.MineTweakerMC;
|
2015-11-01 17:24:35 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import stanhebben.zenscript.annotations.ZenClass;
|
|
|
|
import stanhebben.zenscript.annotations.ZenMethod;
|
|
|
|
import techreborn.api.recipe.IBaseRecipeType;
|
|
|
|
import techreborn.api.recipe.RecipeHandler;
|
|
|
|
import techreborn.api.recipe.machines.AssemblingMachineRecipe;
|
|
|
|
import techreborn.lib.Reference;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
@ZenClass("mods.techreborn.assemblingMachine")
|
|
|
|
public class MTAssemblingMachine {
|
|
|
|
|
2015-11-08 13:15:45 +01:00
|
|
|
@ZenMethod
|
|
|
|
public static void addRecipe(IItemStack output, IIngredient input1, IIngredient input2, int ticktime, int euTick) {
|
|
|
|
ItemStack oInput1 = (ItemStack) MinetweakerCompat.toObject(input1);
|
|
|
|
ItemStack oInput2 = (ItemStack) MinetweakerCompat.toObject(input2);
|
|
|
|
|
|
|
|
AssemblingMachineRecipe r = new AssemblingMachineRecipe(oInput1, oInput2, MinetweakerCompat.toStack(output), ticktime, euTick);
|
|
|
|
|
|
|
|
MineTweakerAPI.apply(new Add(r));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static class Add implements IUndoableAction {
|
|
|
|
private final AssemblingMachineRecipe recipe;
|
|
|
|
|
|
|
|
public Add(AssemblingMachineRecipe recipe) {
|
|
|
|
this.recipe = recipe;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void apply() {
|
|
|
|
RecipeHandler.addRecipe(recipe);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canUndo() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void undo() {
|
|
|
|
RecipeHandler.recipeList.remove(recipe);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String describe() {
|
|
|
|
return "Adding Assembling Machine Recipe for " + recipe.getOutput(0).getDisplayName();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String describeUndo() {
|
|
|
|
return "Removing Assembling Machine Recipe for " + recipe.getOutput(0).getDisplayName();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getOverrideKey() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ZenMethod
|
2015-11-11 09:21:21 +01:00
|
|
|
public static void removeRecipe(IIngredient output) {
|
2015-11-12 09:22:39 +01:00
|
|
|
MineTweakerAPI.apply(new Remove(output));
|
2015-11-08 13:15:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private static class Remove implements IUndoableAction {
|
2015-11-12 09:22:39 +01:00
|
|
|
private final IIngredient output;
|
2015-11-08 13:15:45 +01:00
|
|
|
List<AssemblingMachineRecipe> removedRecipes = new ArrayList<AssemblingMachineRecipe>();
|
|
|
|
|
2015-11-12 09:22:39 +01:00
|
|
|
public Remove(IIngredient output) {
|
2015-11-08 13:15:45 +01:00
|
|
|
this.output = output;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void apply() {
|
|
|
|
for (IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.assemblingMachineRecipe)) {
|
|
|
|
for (ItemStack stack : recipeType.getOutputs()) {
|
2015-11-12 09:22:39 +01:00
|
|
|
if (output.matches(MineTweakerMC.getIItemStack(stack))) {
|
2015-11-08 13:15:45 +01:00
|
|
|
removedRecipes.add((AssemblingMachineRecipe) recipeType);
|
|
|
|
RecipeHandler.recipeList.remove(recipeType);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void undo() {
|
|
|
|
if (removedRecipes != null) {
|
|
|
|
for (AssemblingMachineRecipe recipe : removedRecipes) {
|
|
|
|
if (recipe != null) {
|
|
|
|
RecipeHandler.addRecipe(recipe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String describe() {
|
2015-11-12 09:22:39 +01:00
|
|
|
return "Removing Assembling Machine Recipe";
|
2015-11-08 13:15:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String describeUndo() {
|
2015-11-12 09:22:39 +01:00
|
|
|
return "Re-Adding Assembling Machine Recipe";
|
2015-11-08 13:15:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getOverrideKey() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canUndo() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-11-01 17:24:35 +01:00
|
|
|
}
|