ModTweaker2 Rework

- Revised base classes for IUndoableAction
- Reordered lots of code, so stuck actions should be less frequent
- Added wildcard support to many "remove" methods
- Started working on exist & duplicate checks
This commit is contained in:
Zixxl committed 2015-06-29 16:36:35 +02:00
1 parent f5034b04d8
commit da33cc6fab
112 files changed
+4596 -3522

No files matched your search

@@ -1,14 +1,20 @@
package modtweaker2.mods.botania.handlers;
import static modtweaker2.helpers.InputHelper.toIItemStack;
import static modtweaker2.helpers.InputHelper.toObjects;
import static modtweaker2.helpers.InputHelper.toStack;
import static modtweaker2.helpers.StackHelper.areEqual;
import static modtweaker2.helpers.StackHelper.matches;
import java.util.LinkedList;
import java.util.List;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemStack;
import modtweaker2.helpers.InputHelper;
import modtweaker2.helpers.LogHelper;
import modtweaker2.utils.BaseListAddition;
import modtweaker2.utils.BaseListRemoval;
import net.minecraft.item.ItemStack;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import vazkii.botania.api.BotaniaAPI;
@@ -17,6 +23,11 @@ import vazkii.botania.common.item.block.ItemBlockSpecialFlower;
@ZenClass("mods.botania.Apothecary")
public class Apothecary {
protected static final String name = "Botania Petal";
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void addRecipe(IItemStack output, IIngredient[] input) {
MineTweakerAPI.apply(new Add(new RecipePetals(toStack(output), toObjects(input))));
@@ -24,50 +35,55 @@ public class Apothecary {
@ZenMethod
public static void addRecipe(String output, IIngredient[] input) {
MineTweakerAPI.apply(new Add(new RecipePetals(ItemBlockSpecialFlower.ofType(output), toObjects(input))));
addRecipe(toIItemStack(ItemBlockSpecialFlower.ofType(output)), input);
}
private static class Add extends BaseListAddition {
private static class Add extends BaseListAddition<RecipePetals> {
public Add(RecipePetals recipe) {
super("Botania Petal Recipe", BotaniaAPI.petalRecipes, recipe);
super("Botania Petal", BotaniaAPI.petalRecipes);
recipes.add(recipe);
}
@Override
public String getRecipeInfo() {
return ((RecipePetals) recipe).getOutput().getDisplayName();
public String getRecipeInfo(RecipePetals recipe) {
return InputHelper.getStackDescription(recipe.getOutput());
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void removeRecipe(IItemStack output) {
MineTweakerAPI.apply(new Remove(toStack(output)));
public static void removeRecipe(IIngredient output) {
// Get list of existing recipes, matching with parameter
LinkedList<RecipePetals> result = new LinkedList<RecipePetals>();
for(RecipePetals entry : BotaniaAPI.petalRecipes) {
if(entry != null && entry.getOutput() != null && matches(output, toIItemStack(entry.getOutput()))) {
result.add(entry);
}
}
// Check if we found the recipes and apply the action
if(!result.isEmpty()) {
MineTweakerAPI.apply(new Remove(result));
} else {
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", Apothecary.name, output.toString()));
}
}
@ZenMethod
public static void removeRecipe(String output) {
MineTweakerAPI.apply(new Remove(ItemBlockSpecialFlower.ofType(output)));
removeRecipe(toIItemStack(ItemBlockSpecialFlower.ofType(output)));
}
private static class Remove extends BaseListRemoval {
public Remove(ItemStack stack) {
super("Botania Petal recipe", BotaniaAPI.petalRecipes, stack);
private static class Remove extends BaseListRemoval<RecipePetals> {
public Remove(List<RecipePetals> recipes) {
super(Apothecary.name, BotaniaAPI.petalRecipes, recipes);
}
@Override
public void apply() {
for (RecipePetals r : BotaniaAPI.petalRecipes) {
if (areEqual(r.getOutput(), stack)) {
recipes.add(r);
}
}
super.apply();
}
@Override
public String getRecipeInfo() {
return stack.getDisplayName();
public String getRecipeInfo(RecipePetals recipe) {
return InputHelper.getStackDescription(recipe.getOutput());
}
}
}
@@ -1,14 +1,20 @@
package modtweaker2.mods.botania.handlers;
import static modtweaker2.helpers.InputHelper.toIItemStack;
import static modtweaker2.helpers.InputHelper.toObjects;
import static modtweaker2.helpers.InputHelper.toStack;
import static modtweaker2.helpers.StackHelper.areEqual;
import static modtweaker2.helpers.StackHelper.matches;
import java.util.LinkedList;
import java.util.List;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemStack;
import modtweaker2.helpers.InputHelper;
import modtweaker2.helpers.LogHelper;
import modtweaker2.utils.BaseListAddition;
import modtweaker2.utils.BaseListRemoval;
import net.minecraft.item.ItemStack;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import vazkii.botania.api.BotaniaAPI;
@@ -16,47 +22,57 @@ import vazkii.botania.api.recipe.RecipeElvenTrade;
@ZenClass("mods.botania.ElvenTrade")
public class ElvenTrade {
protected static final String name = "Botania Eleven Trade";
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void addRecipe(IItemStack output, IIngredient[] input) {
MineTweakerAPI.apply(new Add(new RecipeElvenTrade(toStack(output), toObjects(input))));
}
private static class Add extends BaseListAddition {
private static class Add extends BaseListAddition<RecipeElvenTrade> {
public Add(RecipeElvenTrade recipe) {
super("Botania Eleven Trade", BotaniaAPI.elvenTradeRecipes, recipe);
super(ElvenTrade.name, BotaniaAPI.elvenTradeRecipes);
recipes.add(recipe);
}
@Override
public String getRecipeInfo() {
return ((RecipeElvenTrade) recipe).getOutput().getDisplayName();
public String getRecipeInfo(RecipeElvenTrade recipe) {
return InputHelper.getStackDescription(recipe.getOutput());
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void removeRecipe(IItemStack output) {
MineTweakerAPI.apply(new Remove(toStack(output)));
public static void removeRecipe(IIngredient output) {
// Get list of existing recipes, matching with parameter
LinkedList<RecipeElvenTrade> recipes = new LinkedList<RecipeElvenTrade>();
for(RecipeElvenTrade entry : BotaniaAPI.elvenTradeRecipes) {
if(entry != null && entry.getOutput() != null && matches(output, toIItemStack(entry.getOutput()))) {
recipes.add(entry);
}
}
// Check if we found the recipes and apply the action
if(!recipes.isEmpty()) {
MineTweakerAPI.apply(new Remove(recipes));
} else {
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", ElvenTrade.name, output.toString()));
}
}
private static class Remove extends BaseListRemoval {
public Remove(ItemStack stack) {
super("Botania Elven Trade", BotaniaAPI.elvenTradeRecipes, stack);
private static class Remove extends BaseListRemoval<RecipeElvenTrade> {
public Remove(List<RecipeElvenTrade> recipes) {
super(ElvenTrade.name, BotaniaAPI.elvenTradeRecipes, recipes);
}
@Override
public void apply() {
for (RecipeElvenTrade r : BotaniaAPI.elvenTradeRecipes) {
if (r.getOutput() != null && areEqual(r.getOutput(), stack)) {
recipes.add(r);
}
}
super.apply();
}
@Override
public String getRecipeInfo() {
return stack.getDisplayName();
public String getRecipeInfo(RecipeElvenTrade recipe) {
return InputHelper.getStackDescription(recipe.getOutput());
}
}
}
@@ -1,14 +1,20 @@
package modtweaker2.mods.botania.handlers;
import static modtweaker2.helpers.InputHelper.toIItemStack;
import static modtweaker2.helpers.InputHelper.toObject;
import static modtweaker2.helpers.InputHelper.toStack;
import static modtweaker2.helpers.StackHelper.areEqual;
import static modtweaker2.helpers.StackHelper.matches;
import java.util.LinkedList;
import java.util.List;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemStack;
import modtweaker2.helpers.InputHelper;
import modtweaker2.helpers.LogHelper;
import modtweaker2.utils.BaseListAddition;
import modtweaker2.utils.BaseListRemoval;
import net.minecraft.item.ItemStack;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import vazkii.botania.api.BotaniaAPI;
@@ -17,6 +23,9 @@ import vazkii.botania.api.recipe.RecipeManaInfusion;
@ZenClass("mods.botania.ManaInfusion")
public class ManaInfusion {
protected static final String name = "Botania Mana Infusion";
@ZenMethod
public static void addInfusion(IItemStack output, IIngredient input, int mana) {
MineTweakerAPI.apply(new Add(new RecipeManaInfusion(toStack(output), toObject(input), mana)));
@@ -36,42 +45,47 @@ public class ManaInfusion {
MineTweakerAPI.apply(new Add(recipe));
}
private static class Add extends BaseListAddition {
private static class Add extends BaseListAddition<RecipeManaInfusion> {
public Add(RecipeManaInfusion recipe) {
super("Botania Mana Infusion", BotaniaAPI.manaInfusionRecipes, recipe);
super(ManaInfusion.name, BotaniaAPI.manaInfusionRecipes);
recipes.add(recipe);
}
@Override
public String getRecipeInfo() {
return ((RecipeManaInfusion) recipe).getOutput().getDisplayName();
public String getRecipeInfo(RecipeManaInfusion recipe) {
return InputHelper.getStackDescription(recipe.getOutput());
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void removeRecipe(IItemStack output) {
MineTweakerAPI.apply(new Remove(toStack(output)));
public static void removeRecipe(IIngredient output) {
// Get list of existing recipes, matching with parameter
List<RecipeManaInfusion> recipes = new LinkedList<RecipeManaInfusion>();
for (RecipeManaInfusion r : BotaniaAPI.manaInfusionRecipes) {
if (r.getOutput() != null && matches(output, toIItemStack(r.getOutput()))) {
recipes.add(r);
}
}
// Check if we found the recipes and apply the action
if(!recipes.isEmpty()) {
MineTweakerAPI.apply(new Remove(recipes));
} else {
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", ManaInfusion.name, output.toString()));
}
}
private static class Remove extends BaseListRemoval {
public Remove(ItemStack stack) {
super("Botania Mana Infusion", BotaniaAPI.manaInfusionRecipes, stack);
private static class Remove extends BaseListRemoval<RecipeManaInfusion> {
public Remove(List<RecipeManaInfusion> recipes) {
super(ManaInfusion.name, BotaniaAPI.manaInfusionRecipes, recipes);
}
@Override
public void apply() {
for (RecipeManaInfusion r : BotaniaAPI.manaInfusionRecipes) {
if (r.getOutput() != null && areEqual(r.getOutput(), stack)) {
recipes.add(r);
}
}
super.apply();
}
@Override
public String getRecipeInfo() {
return stack.getDisplayName();
public String getRecipeInfo(RecipeManaInfusion recipe) {
return InputHelper.getStackDescription(recipe.getOutput());
}
}
}
@@ -1,14 +1,20 @@
package modtweaker2.mods.botania.handlers;
import static modtweaker2.helpers.InputHelper.toIItemStack;
import static modtweaker2.helpers.InputHelper.toObjects;
import static modtweaker2.helpers.InputHelper.toStack;
import static modtweaker2.helpers.StackHelper.areEqual;
import static modtweaker2.helpers.StackHelper.matches;
import java.util.LinkedList;
import java.util.List;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemStack;
import modtweaker2.helpers.InputHelper;
import modtweaker2.helpers.LogHelper;
import modtweaker2.utils.BaseListAddition;
import modtweaker2.utils.BaseListRemoval;
import net.minecraft.item.ItemStack;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import vazkii.botania.api.BotaniaAPI;
@@ -16,47 +22,58 @@ import vazkii.botania.api.recipe.RecipeRuneAltar;
@ZenClass("mods.botania.RuneAltar")
public class RuneAltar {
protected static final String name = "Botania Rune Altar";
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void addRecipe(IItemStack output, IIngredient[] input, int mana) {
MineTweakerAPI.apply(new Add(new RecipeRuneAltar(toStack(output), mana, toObjects(input))));
}
private static class Add extends BaseListAddition {
private static class Add extends BaseListAddition<RecipeRuneAltar> {
public Add(RecipeRuneAltar recipe) {
super("Botania Rune Altar", BotaniaAPI.runeAltarRecipes, recipe);
super(RuneAltar.name, BotaniaAPI.runeAltarRecipes);
recipes.add(recipe);
}
@Override
public String getRecipeInfo() {
return ((RecipeRuneAltar) recipe).getOutput().getDisplayName();
public String getRecipeInfo(RecipeRuneAltar recipe) {
return InputHelper.getStackDescription(recipe.getOutput());
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void removeRecipe(IItemStack output) {
MineTweakerAPI.apply(new Remove(toStack(output)));
public static void removeRecipe(IIngredient output) {
// Get list of existing recipes, matching with parameter
List<RecipeRuneAltar> recipes = new LinkedList<RecipeRuneAltar>();
for (RecipeRuneAltar r : BotaniaAPI.runeAltarRecipes) {
if (r != null && r.getOutput() != null && matches(output, toIItemStack(r.getOutput()))) {
recipes.add(r);
}
}
// Check if we found the recipes and apply the action
if(!recipes.isEmpty()) {
MineTweakerAPI.apply(new Remove(recipes));
} else {
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", ElvenTrade.name, output.toString()));
}
}
private static class Remove extends BaseListRemoval {
public Remove(ItemStack stack) {
super("Botania Rune Altar", BotaniaAPI.runeAltarRecipes, stack);
private static class Remove extends BaseListRemoval<RecipeRuneAltar> {
public Remove(List<RecipeRuneAltar> recipes) {
super(RuneAltar.name, BotaniaAPI.runeAltarRecipes, recipes);
}
@Override
public void apply() {
for (RecipeRuneAltar r : BotaniaAPI.runeAltarRecipes) {
if (r.getOutput() != null && areEqual(r.getOutput(), stack)) {
recipes.add(r);
}
}
super.apply();
}
@Override
public String getRecipeInfo() {
return stack.getDisplayName();
public String getRecipeInfo(RecipeRuneAltar recipe) {
return InputHelper.getStackDescription(recipe.getOutput());
}
}
}