TechReborn/src/main/java/techreborn/compat/minetweaker/MTCentrifuge.java

186 lines
5.6 KiB
Java
Raw Normal View History

2015-08-27 10:04:41 +02:00
package techreborn.compat.minetweaker;
import minetweaker.IUndoableAction;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemStack;
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.CentrifugeRecipe;
import techreborn.lib.Reference;
2015-10-05 12:18:44 +02:00
import java.util.ArrayList;
2015-08-27 10:04:41 +02:00
import java.util.List;
@ZenClass("mods.techreborn.centrifuge")
public class MTCentrifuge {
2015-11-08 13:15:45 +01:00
@ZenMethod
public static void addRecipe(IItemStack output1, IItemStack output2, IItemStack output3, IItemStack output4, IIngredient input1, IIngredient input2, int ticktime, int euTick) {
ItemStack oInput1 = (ItemStack) MinetweakerCompat.toObject(input1);
ItemStack oInput2 = (ItemStack) MinetweakerCompat.toObject(input2);
CentrifugeRecipe r = new CentrifugeRecipe(oInput1, oInput2, MinetweakerCompat.toStack(output1), MinetweakerCompat.toStack(output2), MinetweakerCompat.toStack(output3), MinetweakerCompat.toStack(output4), ticktime, euTick);
MineTweakerAPI.apply(new Add(r));
}
private static class Add implements IUndoableAction {
private final CentrifugeRecipe recipe;
public Add(CentrifugeRecipe 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 Centrifuge Recipe for " + recipe.getOutput(0).getDisplayName();
}
@Override
public String describeUndo() {
return "Removing Centrifuge Recipe for " + recipe.getOutput(0).getDisplayName();
}
@Override
public Object getOverrideKey() {
return null;
}
}
@ZenMethod
public static void removeRecipe(IItemStack output) {
MineTweakerAPI.apply(new Remove(MinetweakerCompat.toStack(output)));
2015-11-08 13:15:45 +01:00
}
@ZenMethod
public static void removeInputRecipe(IItemStack output) {
MineTweakerAPI.apply(new RemoveInput(MinetweakerCompat.toStack(output)));
2015-11-08 13:15:45 +01:00
}
private static class RemoveInput implements IUndoableAction {
private final ItemStack output;
2015-11-08 13:15:45 +01:00
List<CentrifugeRecipe> removedRecipes = new ArrayList<CentrifugeRecipe>();
public RemoveInput(ItemStack output) {
2015-11-08 13:15:45 +01:00
this.output = output;
}
@Override
public void apply() {
for (IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.centrifugeRecipe)) {
for (ItemStack stack : recipeType.getInputs()) {
if (ItemUtils.isItemEqual(stack, output, true, false)) {
2015-11-08 13:15:45 +01:00
removedRecipes.add((CentrifugeRecipe) recipeType);
RecipeHandler.recipeList.remove(recipeType);
break;
}
}
}
}
@Override
public void undo() {
if (removedRecipes != null) {
for (CentrifugeRecipe recipe : removedRecipes) {
if (recipe != null) {
RecipeHandler.addRecipe(recipe);
}
}
}
}
@Override
public String describe() {
return "Removing Centrifuge Recipe for " + output.getDisplayName();
2015-11-08 13:15:45 +01:00
}
@Override
public String describeUndo() {
return "Re-Adding Centrifuge Recipe for " + output.getDisplayName();
2015-11-08 13:15:45 +01:00
}
@Override
public Object getOverrideKey() {
return null;
}
@Override
public boolean canUndo() {
return true;
}
}
private static class Remove implements IUndoableAction {
private final ItemStack output;
2015-11-08 13:15:45 +01:00
List<CentrifugeRecipe> removedRecipes = new ArrayList<CentrifugeRecipe>();
public Remove(ItemStack output) {
2015-11-08 13:15:45 +01:00
this.output = output;
}
@Override
public void apply() {
for (IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.centrifugeRecipe)) {
for (ItemStack stack : recipeType.getOutputs()) {
if (ItemUtils.isItemEqual(stack, output, true, false)) {
2015-11-08 13:15:45 +01:00
removedRecipes.add((CentrifugeRecipe) recipeType);
RecipeHandler.recipeList.remove(recipeType);
break;
}
}
}
}
@Override
public void undo() {
if (removedRecipes != null) {
for (CentrifugeRecipe recipe : removedRecipes) {
if (recipe != null) {
RecipeHandler.addRecipe(recipe);
}
}
}
}
@Override
public String describe() {
return "Removing Centrifuge Recipe for " + output.getDisplayName();
2015-11-08 13:15:45 +01:00
}
@Override
public String describeUndo() {
return "Re-Adding Centrifuge Recipe for " + output.getDisplayName();
2015-11-08 13:15:45 +01:00
}
@Override
public Object getOverrideKey() {
return null;
}
@Override
public boolean canUndo() {
return true;
}
}
2015-08-27 10:04:41 +02:00
}