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
@@ -1,74 +1,81 @@
|
||||
package modtweaker2.mods.factorization.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.helpers.ReflectionHelper;
|
||||
import modtweaker2.mods.factorization.FactorizationHelper;
|
||||
import modtweaker2.utils.BaseListAddition;
|
||||
import modtweaker2.utils.BaseMultipleListRemoval;
|
||||
import modtweaker2.utils.BaseMultipleListRemoval.Position;
|
||||
import modtweaker2.utils.BaseListRemoval;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
@ZenClass("mods.factorization.SlagFurnace")
|
||||
public class SlagFurnace {
|
||||
|
||||
public static final String name = "Factorization Slag Furnace";
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void addRecipe(IItemStack input, IItemStack output2, double chance2, IItemStack output1, double chance1) {
|
||||
Object recipe = FactorizationHelper.getSlagFurnaceRecipe(toStack(input), (float) chance1, toStack(output1), (float) chance2, toStack(output2));
|
||||
MineTweakerAPI.apply(new Add(toStack(input), recipe));
|
||||
}
|
||||
|
||||
private static class Add extends BaseListAddition {
|
||||
private final ItemStack input;
|
||||
|
||||
private static class Add extends BaseListAddition<Object> {
|
||||
public Add(ItemStack input, Object recipe) {
|
||||
super("Slag Furnace", FactorizationHelper.slag, recipe);
|
||||
this.input = input;
|
||||
super(SlagFurnace.name, FactorizationHelper.slag);
|
||||
recipes.add(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo() {
|
||||
return input.getDisplayName();
|
||||
public String getRecipeInfo(Object recipe) {
|
||||
return InputHelper.getStackDescription((ItemStack) ReflectionHelper.getObject(recipe, "input"));
|
||||
}
|
||||
}
|
||||
|
||||
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void removeRecipe(IItemStack input) {
|
||||
MineTweakerAPI.apply(new Remove(toStack(input), Position.ALL));
|
||||
public static void removeRecipe(IIngredient input) {
|
||||
List<Object> recipes = new LinkedList<Object>();
|
||||
|
||||
for(Object r : FactorizationHelper.slag) {
|
||||
if(r != null) {
|
||||
ItemStack in = (ItemStack) ReflectionHelper.getObject(r, "input");
|
||||
|
||||
if(matches(input, toIItemStack(in))) {
|
||||
recipes.add(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!recipes.isEmpty()) {
|
||||
MineTweakerAPI.apply(new Remove(recipes));
|
||||
} else {
|
||||
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", SlagFurnace.name, input));
|
||||
}
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeFirst(IItemStack output) {
|
||||
MineTweakerAPI.apply(new Remove(toStack(output), Position.FIRST));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeLast(IItemStack output) {
|
||||
MineTweakerAPI.apply(new Remove(toStack(output), Position.LAST));
|
||||
}
|
||||
|
||||
private static class Remove extends BaseMultipleListRemoval {
|
||||
public Remove(ItemStack stack, Position pos) {
|
||||
super("Slag Furnace", FactorizationHelper.slag, stack, pos);
|
||||
private static class Remove extends BaseListRemoval<Object> {
|
||||
public Remove(List<Object> recipes) {
|
||||
super(SlagFurnace.name, FactorizationHelper.slag, recipes);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEqual(Object recipe, Object search) {
|
||||
ItemStack input = (ItemStack) ReflectionHelper.getObject(recipe, "input");
|
||||
if (input != null && areEqual(input, (ItemStack) search)) {
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo() {
|
||||
return ((ItemStack) search).getDisplayName();
|
||||
}
|
||||
@Override
|
||||
public String getRecipeInfo(Object recipe) {
|
||||
return InputHelper.getStackDescription((ItemStack) ReflectionHelper.getObject(recipe, "input"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user