mirror of
https://github.com/GTNewHorizons/ModTweaker.git
synced 2026-11-25 14:44:32 +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,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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user