Some more tweaks

- Code cleanup
- Added ability to remove recipes for a liquid
This commit is contained in:
Zixxl 2015-06-12 10:22:06 +02:00
parent 25da86db52
commit f07b0c014d

View file

@ -15,6 +15,7 @@ import modtweaker2.mods.tconstruct.TConstructHelper;
import modtweaker2.utils.BaseListAddition;
import modtweaker2.utils.BaseListRemoval;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import stanhebben.zenscript.annotations.Optional;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
@ -50,55 +51,44 @@ public class Casting {
//Removing a TConstruct Casting recipe
@ZenMethod
public static void removeBasinRecipe(IItemStack output) {
MineTweakerAPI.apply(new Remove((toStack(output)), TConstructHelper.basinCasting));
MineTweakerAPI.apply(new Remove((toStack(output)), TConstructHelper.basinCasting, RecipeComponent.Output));
}
@ZenMethod
public static void removeTableRecipe(IItemStack output) {
MineTweakerAPI.apply(new Remove((toStack(output)), TConstructHelper.tableCasting));
MineTweakerAPI.apply(new Remove((toStack(output)), TConstructHelper.tableCasting, RecipeComponent.Output));
}
@ZenMethod
public static void removeTableRecipes(IItemStack output) {
MineTweakerAPI.apply(new RemoveAll((toStack(output)), TConstructHelper.tableCasting));
public static void removeBasinLiquid(ILiquidStack fluid) {
MineTweakerAPI.apply(new Remove((toFluid(fluid)), TConstructHelper.basinCasting));
}
//Removes a recipe, apply is never the same for anything, so will always need to override it
private static class Remove extends BaseListRemoval {
public Remove(ItemStack output, ArrayList list) {
super("TConstruct Casting", list, output);
}
//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);
}
}
@Override
public String getRecipeInfo() {
return stack.getDisplayName();
}
@ZenMethod
public static void removeTableLiquid(ILiquidStack fluid) {
MineTweakerAPI.apply(new Remove((toFluid(fluid)), TConstructHelper.tableCasting));
}
@ZenMethod
public static void removeCastRecipes(IItemStack cast) {
MineTweakerAPI.apply(new Remove((toStack(cast)), TConstructHelper.tableCasting, RecipeComponent.Cast));
}
// Removes all matching recipes, apply is never the same for anything, so will always need to override it
private static class RemoveAll extends BaseListRemoval {
private static class Remove extends BaseListRemoval {
protected final LinkedList<CastingRecipe> removedRecipes;
protected final RecipeComponent component;
public RemoveAll(ItemStack output, ArrayList list) {
public Remove(ItemStack output, ArrayList list, RecipeComponent component) {
super("TConstruct Casting", list, output);
removedRecipes = new LinkedList<CastingRecipe>();
this.removedRecipes = new LinkedList<CastingRecipe>();
this.component = component;
}
public Remove(FluidStack output, ArrayList list) {
super("TConstruct Casting", list, output);
this.removedRecipes = new LinkedList<CastingRecipe>();
this.component = RecipeComponent.Material;
}
// Loops through the registry, to find all items that matches, then removes them
@ -106,9 +96,35 @@ public class Casting {
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);
boolean removeRecipie = false;
switch(component)
{
case Cast:
if (r.cast != null && areEqual(r.cast, stack)) {
removeRecipie = true;
}
break;
case Material:
if (r.castingMetal != null && r.castingMetal.isFluidEqual(fluid)) {
removeRecipie = true;
}
break;
case Output:
if (r.output != null && areEqual(r.output, stack)) {
removeRecipie = true;
}
break;
}
if(removeRecipie) {
iterator.remove();
removedRecipes.add(r);
}
}
}
@ -126,46 +142,10 @@ public class Casting {
return stack.getDisplayName();
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Removing TConstruct recipes for a cast
@ZenMethod
public static void removeCastRecipes(IItemStack cast) {
MineTweakerAPI.apply(new RemoveCastRecipies((toStack(cast)), TConstructHelper.tableCasting));
}
private static class RemoveCastRecipies extends BaseListRemoval {
protected final LinkedList<CastingRecipe> removedRecipes;
public RemoveCastRecipies(ItemStack cast, ArrayList list) {
super("TConstruct Casting", list, cast);
removedRecipes = new LinkedList<CastingRecipe>();
}
// Loops through the registry, to find all recipies for a cast, then removes them
@Override
public void apply() {
for (Iterator<CastingRecipe> iterator = ((ArrayList<CastingRecipe>)list).iterator(); iterator.hasNext();) {
CastingRecipe r = iterator.next();
if (r.cast != null && areEqual(r.cast, stack)) {
iterator.remove();
removedRecipes.add(r);
}
}
}
@Override
public void undo() {
for(CastingRecipe recipe : removedRecipes) {
this.list.add(recipe);
}
removedRecipes.clear();
}
@Override
public String getRecipeInfo() {
return stack.getDisplayName();
}
public enum RecipeComponent {
Output,
Cast,
Material
}
}