Some work on recoding MT support

This commit is contained in:
Modmuss50 2015-11-13 13:18:48 +00:00
parent bb2914bf5d
commit 1551164cd6
3 changed files with 204 additions and 208 deletions

View file

@ -1,28 +1,19 @@
package techreborn.compat.minetweaker; package techreborn.compat.minetweaker;
import minetweaker.IUndoableAction;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IIngredient; import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemStack; import minetweaker.api.item.IItemStack;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import reborncore.common.util.ItemUtils;
import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod; import stanhebben.zenscript.annotations.ZenMethod;
import techreborn.api.recipe.IBaseRecipeType;
import techreborn.api.recipe.RecipeHandler;
import techreborn.api.recipe.machines.AlloySmelterRecipe; import techreborn.api.recipe.machines.AlloySmelterRecipe;
import techreborn.lib.Reference; import techreborn.lib.Reference;
import java.util.ArrayList;
import java.util.List;
/** /**
* mods.techreborn.alloySmelter.addRecipe(<minecraft:gold_ingot>, <minecraft:iron_ingot>, <minecraft:diamond>, 20, 100); * mods.techreborn.alloySmelter.addRecipe(<minecraft:gold_ingot>, <minecraft:iron_ingot>, <minecraft:diamond>, 20, 100);
*/ */
@ZenClass("mods.techreborn.alloySmelter") @ZenClass("mods.techreborn.alloySmelter")
public class MTAlloySmelter { public class MTAlloySmelter extends MTGeneric {
@ZenMethod @ZenMethod
public static void addRecipe(IItemStack output, IIngredient input1, IIngredient input2, int ticktime, int euTick) { public static void addRecipe(IItemStack output, IIngredient input1, IIngredient input2, int ticktime, int euTick) {
@ -31,103 +22,11 @@ public class MTAlloySmelter {
AlloySmelterRecipe r = new AlloySmelterRecipe(oInput1, oInput2, MinetweakerCompat.toStack(output), ticktime, euTick); AlloySmelterRecipe r = new AlloySmelterRecipe(oInput1, oInput2, MinetweakerCompat.toStack(output), ticktime, euTick);
MineTweakerAPI.apply(new Add(r)); addRecipe(r);
} }
private static class Add implements IUndoableAction { @Override
private final AlloySmelterRecipe recipe; public String getMachineName() {
return Reference.alloySmelteRecipe;
public Add(AlloySmelterRecipe 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 Alloy Smelter Recipe for " + recipe.getOutput(0).getDisplayName();
}
@Override
public String describeUndo() {
return "Removing Alloy Smelter 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)));
}
private static class Remove implements IUndoableAction {
private final ItemStack output;
List<AlloySmelterRecipe> removedRecipes = new ArrayList<AlloySmelterRecipe>();
public Remove(ItemStack output) {
this.output = output;
}
@Override
public void apply() {
for (IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.alloySmelteRecipe)) {
for (ItemStack stack : recipeType.getOutputs()) {
if (ItemUtils.isItemEqual(stack, output, true, false)) {
removedRecipes.add((AlloySmelterRecipe) recipeType);
RecipeHandler.recipeList.remove(recipeType);
break;
}
}
}
}
@Override
public void undo() {
if (removedRecipes != null) {
for (AlloySmelterRecipe recipe : removedRecipes) {
if (recipe != null) {
RecipeHandler.addRecipe(recipe);
}
}
}
}
@Override
public String describe() {
return "Removing Alloy Smelter Recipe for " + output.getDisplayName();
}
@Override
public String describeUndo() {
return "Re-Adding Alloy Smelter Recipe for " + output.getDisplayName();
}
@Override
public Object getOverrideKey() {
return null;
}
@Override
public boolean canUndo() {
return true;
}
} }
} }

View file

@ -1,23 +1,16 @@
package techreborn.compat.minetweaker; package techreborn.compat.minetweaker;
import minetweaker.IUndoableAction;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IIngredient; import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemStack; import minetweaker.api.item.IItemStack;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import reborncore.common.util.ItemUtils;
import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod; import stanhebben.zenscript.annotations.ZenMethod;
import techreborn.api.recipe.IBaseRecipeType;
import techreborn.api.recipe.RecipeHandler;
import techreborn.api.recipe.machines.AssemblingMachineRecipe; import techreborn.api.recipe.machines.AssemblingMachineRecipe;
import techreborn.lib.Reference; import techreborn.lib.Reference;
import java.util.ArrayList;
import java.util.List;
@ZenClass("mods.techreborn.assemblingMachine") @ZenClass("mods.techreborn.assemblingMachine")
public class MTAssemblingMachine { public class MTAssemblingMachine extends MTGeneric {
@ZenMethod @ZenMethod
public static void addRecipe(IItemStack output, IIngredient input1, IIngredient input2, int ticktime, int euTick) { public static void addRecipe(IItemStack output, IIngredient input1, IIngredient input2, int ticktime, int euTick) {
@ -26,103 +19,13 @@ public class MTAssemblingMachine {
AssemblingMachineRecipe r = new AssemblingMachineRecipe(oInput1, oInput2, MinetweakerCompat.toStack(output), ticktime, euTick); AssemblingMachineRecipe r = new AssemblingMachineRecipe(oInput1, oInput2, MinetweakerCompat.toStack(output), ticktime, euTick);
MineTweakerAPI.apply(new Add(r)); addRecipe(r);
} }
private static class Add implements IUndoableAction { @Override
private final AssemblingMachineRecipe recipe; public String getMachineName() {
return Reference.assemblingMachineRecipe;
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
public static void removeRecipe(IItemStack output) {
MineTweakerAPI.apply(new Remove(MinetweakerCompat.toStack(output)));
}
private static class Remove implements IUndoableAction {
private final ItemStack output;
List<AssemblingMachineRecipe> removedRecipes = new ArrayList<AssemblingMachineRecipe>();
public Remove(ItemStack output) {
this.output = output;
}
@Override
public void apply() {
for (IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.assemblingMachineRecipe)) {
for (ItemStack stack : recipeType.getOutputs()) {
if (ItemUtils.isItemEqual(stack, output, true, false)) {
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() {
return "Removing Assembling Machine Recipe for " + output.getDisplayName();
}
@Override
public String describeUndo() {
return "Re-Adding Assembling Machine Recipe for " + output.getDisplayName();
}
@Override
public Object getOverrideKey() {
return null;
}
@Override
public boolean canUndo() {
return true;
}
}
} }

View file

@ -0,0 +1,194 @@
package techreborn.compat.minetweaker;
import minetweaker.IUndoableAction;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemStack;
import minetweaker.api.minecraft.MineTweakerMC;
import net.minecraft.item.ItemStack;
import reborncore.common.util.ItemUtils;
import stanhebben.zenscript.annotations.ZenMethod;
import techreborn.api.recipe.BaseRecipe;
import techreborn.api.recipe.IBaseRecipeType;
import techreborn.api.recipe.RecipeHandler;
import java.util.ArrayList;
import java.util.List;
public class MTGeneric {
static MTGeneric instance;
public String getMachineName(){
return null;
}
public MTGeneric() {
instance = new MTGeneric();
}
public static void addRecipe(BaseRecipe recipe){
MineTweakerAPI.apply(new Add(recipe));
}
@ZenMethod
public static void removeInputRecipe(IIngredient iIngredient) {
MineTweakerAPI.apply(new RemoveInput(iIngredient, instance.getMachineName()));
}
private static class Add implements IUndoableAction {
private final BaseRecipe recipe;
public Add(BaseRecipe 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 " + recipe.getRecipeName() + " recipe for " + recipe.getOutput(0).getDisplayName();
}
@Override
public String describeUndo() {
return "Removing " + recipe.getRecipeName() + " recipe for " + recipe.getOutput(0).getDisplayName();
}
@Override
public Object getOverrideKey() {
return null;
}
}
@ZenMethod
public static void removeRecipe(IItemStack output, String machineName) {
MineTweakerAPI.apply(new Remove(MinetweakerCompat.toStack(output), machineName));
}
private static class Remove implements IUndoableAction {
private final ItemStack output;
List<BaseRecipe> removedRecipes = new ArrayList<BaseRecipe>();
private final String name;
public Remove(ItemStack output, String machineName) {
this.output = output;
this.name = machineName;
}
@Override
public void apply() {
for (IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(name)) {
for (ItemStack stack : recipeType.getOutputs()) {
if (ItemUtils.isItemEqual(stack, output, true, false)) {
removedRecipes.add((BaseRecipe) recipeType);
RecipeHandler.recipeList.remove(recipeType);
break;
}
}
}
}
@Override
public void undo() {
if (removedRecipes != null) {
for (BaseRecipe recipe : removedRecipes) {
if (recipe != null) {
RecipeHandler.addRecipe(recipe);
}
}
}
}
@Override
public String describe() {
return "Removing " + name + " recipe for " + output.getDisplayName();
}
@Override
public String describeUndo() {
return "Re-Adding " + name +" recipe for " + output.getDisplayName();
}
@Override
public Object getOverrideKey() {
return null;
}
@Override
public boolean canUndo() {
return true;
}
}
private static class RemoveInput implements IUndoableAction {
private final IIngredient output;
List<BaseRecipe> removedRecipes = new ArrayList<BaseRecipe>();
private final String name;
public RemoveInput(IIngredient output, String machineName) {
this.output = output;
this.name = machineName;
}
@Override
public void apply() {
for (IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(name)) {
for (ItemStack stack : recipeType.getInputs()) {
if (output.matches(MineTweakerMC.getIItemStack(stack))) {
removedRecipes.add((BaseRecipe) recipeType);
RecipeHandler.recipeList.remove(recipeType);
break;
}
}
}
}
@Override
public void undo() {
if (removedRecipes != null) {
for (BaseRecipe recipe : removedRecipes) {
if (recipe != null) {
RecipeHandler.addRecipe(recipe);
}
}
}
}
@Override
public String describe() {
return "Removing " + name + " recipe";
}
@Override
public String describeUndo() {
return "Re-Adding " + name +" recipe";
}
@Override
public Object getOverrideKey() {
return null;
}
@Override
public boolean canUndo() {
return true;
}
}
}