Tweaks for TinkersConstruct casting
- Fixed: Script crash if recipe is not present (maybe fixes issue #144) - Added: Support to remove all recipies
This commit is contained in:
parent
892524e253
commit
4b37bbc7b8
1 changed files with 52 additions and 1 deletions
|
@ -5,6 +5,8 @@ import static modtweaker2.helpers.InputHelper.toStack;
|
|||
import static modtweaker2.helpers.StackHelper.areEqual;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
|
@ -50,11 +52,21 @@ public class Casting {
|
|||
public static void removeBasinRecipe(IItemStack output) {
|
||||
MineTweakerAPI.apply(new Remove((toStack(output)), TConstructHelper.basinCasting));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeBasinRecipes(IItemStack output) {
|
||||
MineTweakerAPI.apply(new RemoveAll((toStack(output)), TConstructHelper.basinCasting));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeTableRecipe(IItemStack output) {
|
||||
MineTweakerAPI.apply(new Remove((toStack(output)), TConstructHelper.tableCasting));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeTableRecipes(IItemStack output) {
|
||||
MineTweakerAPI.apply(new RemoveAll((toStack(output)), TConstructHelper.tableCasting));
|
||||
}
|
||||
|
||||
//Removes a recipe, apply is never the same for anything, so will always need to override it
|
||||
private static class Remove extends BaseListRemoval {
|
||||
|
@ -65,14 +77,53 @@ public class Casting {
|
|||
//Loops through the registry, to find the item that matches, saves that recipe then removes it
|
||||
@Override
|
||||
public void apply() {
|
||||
recipe = null;
|
||||
|
||||
for (CastingRecipe r : (ArrayList<CastingRecipe>) list) {
|
||||
if (r.output != null && areEqual(r.output, stack)) {
|
||||
recipe = r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (recipe != null) {
|
||||
list.remove(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
list.remove(recipe);
|
||||
@Override
|
||||
public String getRecipeInfo() {
|
||||
return stack.getDisplayName();
|
||||
}
|
||||
}
|
||||
|
||||
// Removes all matching recipes, apply is never the same for anything, so will always need to override it
|
||||
private static class RemoveAll extends BaseListRemoval {
|
||||
protected final LinkedList<CastingRecipe> removedRecipes;
|
||||
|
||||
public RemoveAll(ItemStack output, ArrayList list) {
|
||||
super("TConstruct Casting", list, output);
|
||||
removedRecipes = new LinkedList<CastingRecipe>();
|
||||
}
|
||||
|
||||
// Loops through the registry, to find all items that matches, then removes them
|
||||
@Override
|
||||
public void apply() {
|
||||
for (Iterator<CastingRecipe> iterator = ((ArrayList<CastingRecipe>)list).iterator(); iterator.hasNext();) {
|
||||
CastingRecipe r = iterator.next();
|
||||
if (r.output != null && areEqual(r.output, stack)) {
|
||||
iterator.remove();
|
||||
removedRecipes.add(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
for(CastingRecipe recipe : removedRecipes) {
|
||||
this.list.add(recipe);
|
||||
}
|
||||
removedRecipes.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue