Files
ModTweaker/src/main/java/modtweaker2/mods/railcraft/handlers/RockCrusher.java
T
Zixxl da33cc6fab 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
2015-06-29 16:36:35 +02:00

80 lines
2.9 KiB
Java

package modtweaker2.mods.railcraft.handlers;
import static modtweaker2.helpers.InputHelper.toIItemStack;
import static modtweaker2.helpers.InputHelper.toStack;
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 mods.railcraft.api.crafting.IRockCrusherRecipe;
import modtweaker2.helpers.InputHelper;
import modtweaker2.helpers.LogHelper;
import modtweaker2.mods.railcraft.RailcraftHelper;
import modtweaker2.utils.BaseListAddition;
import modtweaker2.utils.BaseListRemoval;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
@ZenClass("mods.railcraft.RockCrusher")
public class RockCrusher {
public static final String name = "Railcraft Rock Crusher";
@ZenMethod
public static void addRecipe(IItemStack input, boolean matchDamage, boolean matchNBT, IItemStack[] output, double[] chances) {
IRockCrusherRecipe recipe = RailcraftHelper.getRockCrusherRecipe(toStack(input), matchDamage, matchNBT);
for (int i = 0; i < output.length; i++) {
recipe.addOutput(toStack(output[i]), (float) chances[i]);
}
MineTweakerAPI.apply(new Add(recipe));
}
private static class Add extends BaseListAddition<IRockCrusherRecipe> {
public Add(IRockCrusherRecipe recipe) {
super(RockCrusher.name, (List<IRockCrusherRecipe>)RailcraftHelper.crusher);
recipes.add(recipe);
}
@Override
public String getRecipeInfo(IRockCrusherRecipe recipe) {
return InputHelper.getStackDescription(recipe.getInput());
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void removeRecipe(IIngredient input) {
List<IRockCrusherRecipe> recipes = new LinkedList<IRockCrusherRecipe>();
for (IRockCrusherRecipe r : RailcraftHelper.crusher) {
if (r.getInput() != null && matches(input, toIItemStack(r.getInput()))) {
recipes.add(r);
}
}
if(!recipes.isEmpty()) {
MineTweakerAPI.apply(new Remove(recipes));
} else {
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", RockCrusher.name, input.toString()));
}
}
private static class Remove extends BaseListRemoval<IRockCrusherRecipe> {
public Remove(List<IRockCrusherRecipe> recipes) {
super("Rock Crusher", (List<IRockCrusherRecipe>)RailcraftHelper.crusher, recipes);
}
@Override
public String getRecipeInfo(IRockCrusherRecipe recipe) {
return InputHelper.getStackDescription(recipe.getInput());
}
}
}