mirror of
https://github.com/GTNewHorizons/ModTweaker.git
synced 2026-11-20 12:29:45 +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
@@ -2,18 +2,23 @@ package modtweaker2.mods.forestry.handlers;
|
||||
|
||||
import static modtweaker2.helpers.InputHelper.getFluid;
|
||||
import static modtweaker2.helpers.InputHelper.toFluid;
|
||||
import static modtweaker2.helpers.InputHelper.toILiquidStack;
|
||||
import static modtweaker2.helpers.InputHelper.toStack;
|
||||
import static modtweaker2.helpers.InputHelper.toStacks;
|
||||
import static modtweaker2.helpers.StackHelper.matches;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
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.minecraftforge.fluids.FluidStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import forestry.factory.gadgets.MachineSqueezer;
|
||||
@@ -22,6 +27,10 @@ import forestry.factory.gadgets.MachineSqueezer.RecipeManager;
|
||||
|
||||
@ZenClass("mods.forestry.Squeezer")
|
||||
public class Squeezer {
|
||||
|
||||
public static final String name = "Forestry Squeezer";
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void addRecipe(int timePerItem, IItemStack[] resources, ILiquidStack liquid, IItemStack remnants, int chance) {
|
||||
@@ -30,38 +39,53 @@ public class Squeezer {
|
||||
MachineSqueezer.RecipeManager.recipeInputs.addAll(Arrays.asList(toStacks(resources)));
|
||||
}
|
||||
|
||||
private static class Add extends BaseListAddition {
|
||||
private static class Add extends BaseListAddition<Recipe> {
|
||||
public Add(Recipe recipe) {
|
||||
super("Forestry Squeezer", MachineSqueezer.RecipeManager.recipes, recipe);
|
||||
super(Squeezer.name, MachineSqueezer.RecipeManager.recipes);
|
||||
recipes.add(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo() {
|
||||
return ((Recipe) recipe).liquid.getLocalizedName();
|
||||
public String getRecipeInfo(Recipe recipe) {
|
||||
return InputHelper.getStackDescription(recipe.liquid);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void removeRecipe(ILiquidStack liquid) {
|
||||
MineTweakerAPI.apply(new Remove(MachineSqueezer.RecipeManager.recipes, toFluid(liquid)));
|
||||
public static void removeRecipe(IIngredient liquid) {
|
||||
List<Recipe> recipes = new LinkedList<Recipe>();
|
||||
|
||||
for (Recipe r : RecipeManager.recipes) {
|
||||
if (r != null && r.liquid != null && matches(liquid, toILiquidStack(r.liquid))) {
|
||||
recipes.add(r);
|
||||
}
|
||||
}
|
||||
|
||||
if(!recipes.isEmpty()) {
|
||||
MineTweakerAPI.apply(new Remove(recipes));
|
||||
} else {
|
||||
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", Squeezer.name, liquid.toString()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class Remove extends BaseListRemoval {
|
||||
|
||||
public Remove(List list, FluidStack liquid) {
|
||||
super(list, liquid);
|
||||
private static class Remove extends BaseListRemoval<Recipe> {
|
||||
public Remove(List<Recipe> recipes) {
|
||||
super(Squeezer.name, MachineSqueezer.RecipeManager.recipes, recipes);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (Recipe r : RecipeManager.recipes) {
|
||||
if (r.liquid != null && r.liquid.isFluidEqual(fluid)) {
|
||||
recipes.add(r);
|
||||
}
|
||||
}
|
||||
|
||||
super.apply();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo(Recipe recipe) {
|
||||
return InputHelper.getStackDescription(recipe.liquid);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user