mirror of
https://github.com/GTNewHorizons/ModTweaker.git
synced 2026-11-26 15:13:05 +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,21 +1,28 @@
|
||||
package modtweaker2.mods.pneumaticcraft.handlers;
|
||||
|
||||
import static modtweaker2.helpers.InputHelper.toIItemStack;
|
||||
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 pneumaticCraft.api.recipe.AssemblyRecipe;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
@ZenClass("mods.pneumaticcraft.Assembly")
|
||||
public class Assembly {
|
||||
|
||||
public static final String name = "PneumaticCraft Assembly";
|
||||
|
||||
@ZenMethod
|
||||
public static void addDrillRecipe(IItemStack input, IItemStack output) {
|
||||
MineTweakerAPI.apply(new Add(new AssemblyRecipe(toStack(input), toStack(output)), AssemblyRecipe.drillRecipes));
|
||||
@@ -31,53 +38,59 @@ public class Assembly {
|
||||
MineTweakerAPI.apply(new Add(new AssemblyRecipe(toStack(input), toStack(output)), AssemblyRecipe.drillLaserRecipes));
|
||||
}
|
||||
|
||||
private static class Add extends BaseListAddition {
|
||||
public Add(AssemblyRecipe recipe, List list) {
|
||||
super("Pneumaticraft Assembly", list, recipe);
|
||||
private static class Add extends BaseListAddition<AssemblyRecipe> {
|
||||
public Add(AssemblyRecipe recipe, List<AssemblyRecipe> list) {
|
||||
super(Assembly.name, list);
|
||||
recipes.add(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo() {
|
||||
return ((AssemblyRecipe) recipe).getOutput().getDisplayName();
|
||||
public String getRecipeInfo(AssemblyRecipe recipe) {
|
||||
return InputHelper.getStackDescription(recipe.getOutput());
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void removeDrillRecipe(IItemStack output) {
|
||||
MineTweakerAPI.apply(new Remove(toStack(output), AssemblyRecipe.drillRecipes));
|
||||
public static void removeDrillRecipe(IIngredient output) {
|
||||
removeRecipe(AssemblyRecipe.drillRecipes, output);
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeLaserRecipe(IItemStack output) {
|
||||
MineTweakerAPI.apply(new Remove(toStack(output), AssemblyRecipe.laserRecipes));
|
||||
public static void removeLaserRecipe(IIngredient output) {
|
||||
removeRecipe(AssemblyRecipe.laserRecipes, output);
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeLaserDrillRecipe(IItemStack output) {
|
||||
MineTweakerAPI.apply(new Remove(toStack(output), AssemblyRecipe.drillLaserRecipes));
|
||||
public static void removeLaserDrillRecipe(IIngredient output) {
|
||||
removeRecipe(AssemblyRecipe.drillLaserRecipes, output);
|
||||
}
|
||||
|
||||
private static class Remove extends BaseListRemoval {
|
||||
public Remove(ItemStack stack, List list) {
|
||||
super("Pneumaticraft Assembly", list, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (AssemblyRecipe r : (List<AssemblyRecipe>) list) {
|
||||
if (r.getOutput() != null && areEqual(r.getOutput(), stack)) {
|
||||
recipes.add(r);
|
||||
}
|
||||
|
||||
public static void removeRecipe(List<AssemblyRecipe> list, IIngredient output) {
|
||||
List<AssemblyRecipe> recipes = new LinkedList<AssemblyRecipe>();
|
||||
|
||||
for (AssemblyRecipe r : list) {
|
||||
if (r.getOutput() != null && matches(output, toIItemStack(r.getOutput()))) {
|
||||
recipes.add(r);
|
||||
}
|
||||
}
|
||||
|
||||
if(!recipes.isEmpty()) {
|
||||
MineTweakerAPI.apply(new Remove(list, recipes));
|
||||
} else {
|
||||
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", Assembly.name, output.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
super.apply();
|
||||
private static class Remove extends BaseListRemoval<AssemblyRecipe> {
|
||||
public Remove(List<AssemblyRecipe> list, List<AssemblyRecipe> recipes) {
|
||||
super(Assembly.name, list, recipes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo() {
|
||||
return stack.getDisplayName();
|
||||
public String getRecipeInfo(AssemblyRecipe recipe) {
|
||||
return InputHelper.getStackDescription(recipe.getOutput());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user