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,22 +1,34 @@
package modtweaker2.mods.mariculture.handlers;
import static modtweaker2.helpers.InputHelper.toFluid;
import static modtweaker2.helpers.InputHelper.toIItemStack;
import static modtweaker2.helpers.InputHelper.toILiquidStack;
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 mariculture.api.core.MaricultureHandlers;
import mariculture.api.core.RecipeVat;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemStack;
import minetweaker.api.liquid.ILiquidStack;
import modtweaker2.helpers.InputHelper;
import modtweaker2.helpers.LogHelper;
import modtweaker2.utils.BaseListAddition;
import modtweaker2.utils.BaseListRemoval;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
@ZenClass("mods.mariculture.Vat")
public class Vat {
public static final String name = "Mariculture Vat";
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Adding a Mariculture Vat recipe
@ZenMethod
public static void addRecipe(ILiquidStack fluid1, ILiquidStack fluid2, ILiquidStack outputFluid, int time) {
@@ -64,74 +76,82 @@ public class Vat {
}
// Passes the list to the base list implementation, and adds the recipe
private static class Add extends BaseListAddition {
private static class Add extends BaseListAddition<RecipeVat> {
public Add(RecipeVat recipe) {
super("Mariculture Vat", MaricultureHandlers.vat.getRecipes(), recipe);
super("Mariculture Vat", MaricultureHandlers.vat.getRecipes());
recipes.add(recipe);
}
@Override
public String getRecipeInfo() {
if (((RecipeVat) recipe).outputItem != null)
return ((RecipeVat) recipe).outputItem.getDisplayName();
else
return ((RecipeVat) recipe).outputFluid.getFluid().getLocalizedName();
public String getRecipeInfo(RecipeVat recipe) {
if(recipe.outputItem != null) {
return InputHelper.getStackDescription(recipe.outputItem);
} else {
return InputHelper.getStackDescription(recipe.outputFluid);
}
}
}
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Removing a Mariculture Vat recipe
@ZenMethod
public static void removeRecipe(IItemStack outputItem) {
MineTweakerAPI.apply(new Remove(toStack(outputItem), null));
public static void removeRecipe(IIngredient ingredient) {
List<RecipeVat> recipes = new LinkedList<RecipeVat>();
for(RecipeVat r : MaricultureHandlers.vat.getRecipes()) {
if(r != null) {
if(r.outputItem != null && matches(ingredient, toIItemStack(r.outputItem))) {
recipes.add(r);
}
else if(r.outputFluid != null && matches(ingredient, toILiquidStack(r.outputFluid))) {
recipes.add(r);
}
}
}
if(!recipes.isEmpty()) {
MineTweakerAPI.apply(new Remove(recipes));
} else {
LogHelper.logWarning(String.format("No %s Recipes found for %s. Command ignored!", Vat.name, ingredient.toString()));
}
}
@ZenMethod
public static void removeRecipe(ILiquidStack outputFluid) {
MineTweakerAPI.apply(new Remove(null, toFluid(outputFluid)));
}
@ZenMethod
public static void removeRecipe(IItemStack outputItem, ILiquidStack outputFluid) {
MineTweakerAPI.apply(new Remove(toStack(outputItem), toFluid(outputFluid)));
public static void removeRecipe(IIngredient outputItem, IIngredient outputFluid) {
List<RecipeVat> recipes = new LinkedList<RecipeVat>();
for (RecipeVat r : MaricultureHandlers.vat.getRecipes()) {
if (r != null) {
if (r.outputItem != null && matches(outputItem, toIItemStack(r.outputItem))) {
if (r.outputFluid != null && matches(outputFluid, toILiquidStack(r.outputFluid))) {
recipes.add(r);
}
}
}
}
if(!recipes.isEmpty()) {
MineTweakerAPI.apply(new Remove(recipes));
} else {
LogHelper.logWarning(String.format("No %s Recipes found for %s and %s. Command ignored!", Vat.name, outputItem.toString(), outputFluid.toString()));
}
}
// Removes a recipe, apply is never the same for anything, so will always
// need to override it
private static class Remove extends BaseListRemoval {
private FluidStack fluid = null;
public Remove(ItemStack stack, FluidStack fluid) {
super("Mariculture Vat", MaricultureHandlers.vat.getRecipes(), stack);
if (fluid != null)
this.fluid = fluid;
private static class Remove extends BaseListRemoval<RecipeVat> {
public Remove(List<RecipeVat> recipes) {
super("Mariculture Vat", MaricultureHandlers.vat.getRecipes(), recipes);
}
// Loops through the registry, to find the item that matches, saves that
// recipe then removes it
@Override
public void apply() {
for (RecipeVat r : MaricultureHandlers.vat.getRecipes()) {
if (r != null)
if (r.outputItem != null && stack != null && areEqual(r.outputItem, stack)) {
if (r.outputFluid == null || (fluid != null && r.outputFluid.isFluidStackIdentical(fluid))) {
recipes.add(r);
break;
}
}
if ((r.outputFluid != null && fluid != null && r.outputFluid.isFluidStackIdentical(fluid))) {
recipes.add(r);
break;
}
}
super.apply();
}
@Override
public String getRecipeInfo() {
return stack != null ? stack.getDisplayName() : fluid.getFluid().getLocalizedName();
}
@Override
public String getRecipeInfo(RecipeVat recipe) {
if(recipe.outputItem != null) {
return InputHelper.getStackDescription(recipe.outputItem);
} else {
return InputHelper.getStackDescription(recipe.outputFluid);
}
}
}
}