2015-08-27 11:22:17 +02:00
|
|
|
package techreborn.compat.minetweaker;
|
|
|
|
|
|
|
|
import minetweaker.IUndoableAction;
|
|
|
|
import minetweaker.MineTweakerAPI;
|
|
|
|
import minetweaker.api.item.IIngredient;
|
|
|
|
import minetweaker.api.item.IItemStack;
|
|
|
|
import minetweaker.api.liquid.ILiquidStack;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
2015-11-13 09:28:32 +01:00
|
|
|
import reborncore.common.util.ItemUtils;
|
2015-08-27 11:22:17 +02:00
|
|
|
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.IndustrialSawmillRecipe;
|
|
|
|
import techreborn.lib.Reference;
|
|
|
|
|
2015-10-05 12:18:44 +02:00
|
|
|
import java.util.ArrayList;
|
2015-08-27 11:22:17 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
@ZenClass("mods.techreborn.industrialSawmill")
|
|
|
|
public class MTIndustrialSawmill {
|
|
|
|
|
|
|
|
@ZenMethod
|
2015-11-08 13:15:45 +01:00
|
|
|
public static void addRecipe(IItemStack output1, IItemStack output2, IItemStack output3, IIngredient input1, IIngredient input2, ILiquidStack fluid, int ticktime, int euTick) {
|
|
|
|
addRecipe(output1, output2, output3, input1, input2, fluid, ticktime, euTick, true);
|
2015-08-27 11:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@ZenMethod
|
2015-11-08 13:15:45 +01:00
|
|
|
public static void addRecipe(IItemStack output1, IItemStack output2, IItemStack output3, IIngredient input1, IIngredient input2, int ticktime, int euTick) {
|
|
|
|
addRecipe(output1, output2, output3, input1, input2, null, ticktime, euTick, true);
|
2015-08-27 11:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@ZenMethod
|
2015-11-08 13:15:45 +01:00
|
|
|
public static void addRecipe(IItemStack output1, IItemStack output2, IItemStack output3, IIngredient input1, IIngredient input2, int ticktime, int euTick, boolean useOreDic) {
|
|
|
|
addRecipe(output1, output2, output3, input1, input2, null, ticktime, euTick, useOreDic);
|
2015-08-27 11:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@ZenMethod
|
2015-11-08 13:15:45 +01:00
|
|
|
public static void addRecipe(IItemStack output1, IItemStack output2, IItemStack output3, IIngredient input1, IIngredient input2, ILiquidStack fluid, int ticktime, int euTick, boolean useOreDic) {
|
2015-08-27 11:22:17 +02:00
|
|
|
ItemStack oInput1 = (ItemStack) MinetweakerCompat.toObject(input1);
|
|
|
|
|
|
|
|
ItemStack oInput2 = (ItemStack) MinetweakerCompat.toObject(input2);
|
|
|
|
|
|
|
|
FluidStack fluidStack = null;
|
2015-11-08 13:15:45 +01:00
|
|
|
if (fluid != null) {
|
2015-08-27 11:22:17 +02:00
|
|
|
fluidStack = MinetweakerCompat.toFluidStack(fluid);
|
|
|
|
}
|
|
|
|
|
2015-11-08 13:15:45 +01:00
|
|
|
IndustrialSawmillRecipe r = new IndustrialSawmillRecipe(oInput1, oInput2, fluidStack, MinetweakerCompat.toStack(output1), MinetweakerCompat.toStack(output2), MinetweakerCompat.toStack(output3), ticktime, euTick, useOreDic);
|
2015-08-27 11:22:17 +02:00
|
|
|
|
|
|
|
MineTweakerAPI.apply(new Add(r));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static class Add implements IUndoableAction {
|
|
|
|
private final IndustrialSawmillRecipe recipe;
|
|
|
|
|
|
|
|
public Add(IndustrialSawmillRecipe 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 Sawmill Recipe for " + recipe.getOutput(0).getDisplayName();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String describeUndo() {
|
|
|
|
return "Removing Sawmill Recipe for " + recipe.getOutput(0).getDisplayName();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getOverrideKey() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ZenMethod
|
2015-11-13 09:27:02 +01:00
|
|
|
public static void removeRecipe(IItemStack output) {
|
|
|
|
MineTweakerAPI.apply(new Remove(MinetweakerCompat.toStack(output)));
|
2015-08-27 11:22:17 +02:00
|
|
|
}
|
2015-11-08 13:15:45 +01:00
|
|
|
|
|
|
|
private static class Remove implements IUndoableAction {
|
2015-11-13 09:26:51 +01:00
|
|
|
private final ItemStack output;
|
2015-10-05 12:18:44 +02:00
|
|
|
List<IndustrialSawmillRecipe> removedRecipes = new ArrayList<IndustrialSawmillRecipe>();
|
2015-11-08 13:15:45 +01:00
|
|
|
|
2015-11-13 09:26:51 +01:00
|
|
|
public Remove(ItemStack output) {
|
2015-08-27 11:22:17 +02:00
|
|
|
this.output = output;
|
|
|
|
}
|
2015-11-08 13:15:45 +01:00
|
|
|
|
2015-08-27 11:22:17 +02:00
|
|
|
@Override
|
2015-11-08 13:15:45 +01:00
|
|
|
public void apply() {
|
|
|
|
for (IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.industrialSawmillRecipe)) {
|
|
|
|
for (ItemStack stack : recipeType.getOutputs()) {
|
2015-11-13 09:26:51 +01:00
|
|
|
if (ItemUtils.isItemEqual(stack, output, true, false)) {
|
2015-08-27 11:22:17 +02:00
|
|
|
removedRecipes.add((IndustrialSawmillRecipe) recipeType);
|
|
|
|
RecipeHandler.recipeList.remove(recipeType);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-08 13:15:45 +01:00
|
|
|
|
2015-08-27 11:22:17 +02:00
|
|
|
@Override
|
2015-11-08 13:15:45 +01:00
|
|
|
public void undo() {
|
|
|
|
if (removedRecipes != null) {
|
|
|
|
for (IndustrialSawmillRecipe recipe : removedRecipes) {
|
|
|
|
if (recipe != null) {
|
2015-08-27 11:22:17 +02:00
|
|
|
RecipeHandler.addRecipe(recipe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-11-08 13:15:45 +01:00
|
|
|
|
2015-08-27 11:22:17 +02:00
|
|
|
@Override
|
2015-11-08 13:15:45 +01:00
|
|
|
public String describe() {
|
2015-11-13 09:26:51 +01:00
|
|
|
return "Removing Sawmill Recipe for " + output.getDisplayName();
|
2015-08-27 11:22:17 +02:00
|
|
|
}
|
2015-11-08 13:15:45 +01:00
|
|
|
|
2015-08-27 11:22:17 +02:00
|
|
|
@Override
|
2015-11-08 13:15:45 +01:00
|
|
|
public String describeUndo() {
|
2015-11-13 09:26:51 +01:00
|
|
|
return "Re-Adding Sawmill Recipe for " + output.getDisplayName();
|
2015-08-27 11:22:17 +02:00
|
|
|
}
|
2015-11-08 13:15:45 +01:00
|
|
|
|
2015-08-27 11:22:17 +02:00
|
|
|
@Override
|
2015-11-08 13:15:45 +01:00
|
|
|
public Object getOverrideKey() {
|
2015-08-27 11:22:17 +02:00
|
|
|
return null;
|
|
|
|
}
|
2015-11-08 13:15:45 +01:00
|
|
|
|
2015-08-27 11:22:17 +02:00
|
|
|
@Override
|
2015-11-08 13:15:45 +01:00
|
|
|
public boolean canUndo() {
|
2015-08-27 11:22:17 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|