mirror of
https://github.com/GTNewHorizons/ModTweaker.git
synced 2026-11-28 07:55:58 +00:00
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:
1 parent
f5034b04d8
commit
da33cc6fab
112 files changed
+4596
-3522
No files matched your search
@@ -1,16 +1,21 @@
|
||||
package modtweaker2.mods.thaumcraft.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.mods.thaumcraft.ThaumcraftHelper;
|
||||
import modtweaker2.utils.BaseListAddition;
|
||||
import modtweaker2.utils.BaseListRemoval;
|
||||
import modtweaker2.utils.TweakerPlugin;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import thaumcraft.api.ThaumcraftApi;
|
||||
@@ -18,52 +23,56 @@ import thaumcraft.api.crafting.CrucibleRecipe;
|
||||
|
||||
@ZenClass("mods.thaumcraft.Crucible")
|
||||
public class Crucible {
|
||||
|
||||
public static final String name = "Thaumcraft Crucible";
|
||||
|
||||
@ZenMethod
|
||||
public static void addRecipe(String key, IItemStack result, IIngredient catalyst, String aspects) {
|
||||
|
||||
MineTweakerAPI.apply(new Add(new CrucibleRecipe(key, toStack(result), toObject(catalyst), ThaumcraftHelper.parseAspects(aspects))));
|
||||
MineTweakerAPI.apply(new Add(new CrucibleRecipe(key, toStack(result), toObject(catalyst), ThaumcraftHelper.parseAspects(aspects))));
|
||||
}
|
||||
|
||||
private static class Add extends BaseListAddition {
|
||||
|
||||
private static class Add extends BaseListAddition<CrucibleRecipe> {
|
||||
public Add(CrucibleRecipe recipe) {
|
||||
super("Thaumcraft Crucible", ThaumcraftApi.getCraftingRecipes(), recipe);
|
||||
super(Crucible.name, ThaumcraftApi.getCraftingRecipes());
|
||||
recipes.add(recipe);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo() {
|
||||
return ((CrucibleRecipe) recipe).getRecipeOutput().getDisplayName();
|
||||
protected String getRecipeInfo(CrucibleRecipe recipe) {
|
||||
return InputHelper.getStackDescription(recipe.getRecipeOutput());
|
||||
}
|
||||
}
|
||||
|
||||
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void removeRecipe(IItemStack output) {
|
||||
|
||||
MineTweakerAPI.apply(new Remove(toStack(output)));
|
||||
public static void removeRecipe(IIngredient output) {
|
||||
List<CrucibleRecipe> recipes = new LinkedList<CrucibleRecipe>();
|
||||
|
||||
for (Object o : ThaumcraftApi.getCraftingRecipes()) {
|
||||
if (o instanceof CrucibleRecipe) {
|
||||
CrucibleRecipe r = (CrucibleRecipe) o;
|
||||
if (r.getRecipeOutput() != null && matches(output, toIItemStack(r.getRecipeOutput()))) {
|
||||
recipes.add(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!recipes.isEmpty()) {
|
||||
MineTweakerAPI.apply(new Remove(recipes));
|
||||
} else {
|
||||
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", Crucible.name, output.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
private static class Remove extends BaseListRemoval {
|
||||
public Remove(ItemStack stack) {
|
||||
super("Thaumcraft Crucible", ThaumcraftApi.getCraftingRecipes(), stack);
|
||||
private static class Remove extends BaseListRemoval<CrucibleRecipe> {
|
||||
public Remove(List<CrucibleRecipe> recipes) {
|
||||
super(Crucible.name, ThaumcraftApi.getCraftingRecipes(), recipes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (Object o : ThaumcraftApi.getCraftingRecipes()) {
|
||||
if (o instanceof CrucibleRecipe) {
|
||||
CrucibleRecipe r = (CrucibleRecipe) o;
|
||||
if (r.getRecipeOutput() != null && areEqual(r.getRecipeOutput(), stack)) {
|
||||
recipes.add(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo() {
|
||||
return stack.getDisplayName();
|
||||
}
|
||||
@Override
|
||||
protected String getRecipeInfo(CrucibleRecipe recipe) {
|
||||
return InputHelper.getStackDescription(recipe.getRecipeOutput());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user