Merge pull request #153 from Zixxl/master

Reworked BaseListRemoval
This commit is contained in:
Jared 2015-06-19 00:22:09 +02:00
commit 801990af69
40 changed files with 228 additions and 284 deletions

View file

@ -41,24 +41,23 @@ public class Grind {
}
private static class Remove extends BaseListRemoval {
public Remove(ItemStack stack) {
super(AEApi.instance().registries().grinder().getRecipes(), stack);
super("Applied Energistics 2 Grinder", AEApi.instance().registries().grinder().getRecipes(), stack);
}
@Override
public void apply() {
ArrayList<IGrinderEntry> toRemove = new ArrayList<IGrinderEntry>();
for (IGrinderEntry r : AEApi.instance().registries().grinder().getRecipes()) {
if (r.getOutput().isItemEqual(stack)) {
toRemove.add(r);
recipes.add(r);
}
}
for (IGrinderEntry r : toRemove) {
AEApi.instance().registries().grinder().getRecipes().remove(r);
}
super.apply();
}
@Override
public String getRecipeInfo() {
return stack.getDisplayName();
}
}

View file

@ -55,25 +55,23 @@ public class Inscriber {
}
public static class Remove extends BaseListRemoval {
public Remove(ItemStack stack) {
super(stack.getUnlocalizedName(), AEApi.instance().registries().inscriber().getRecipes(), stack);
super("Applied Energistics 2 Inscriber", AEApi.instance().registries().inscriber().getRecipes(), stack);
}
@Override
public void apply() {
ArrayList<IInscriberRecipe> recipesToRemove = new ArrayList<IInscriberRecipe>();
for (IInscriberRecipe recipe : AEApi.instance().registries().inscriber().getRecipes()) {
if (recipe != null && recipe.getOutput() != null && recipe.getOutput().isItemEqual(stack)) {
recipesToRemove.add(recipe);
recipes.add(recipe);
}
}
for (IInscriberRecipe recipe : recipesToRemove) {
AEApi.instance().registries().inscriber().removeRecipe(recipe);
}
super.apply();
}
@Override
public String getRecipeInfo() {
return stack.getDisplayName();
}
}
}

View file

@ -44,8 +44,6 @@ public class Pylon {
}
private static class Remove extends BaseListRemoval {
ArrayList<PylonRecipe> recipesToRemove = new ArrayList<PylonRecipe>();
public Remove(ItemStack stack) {
super(PylonRecipeRegistry.recipes, stack);
}
@ -54,13 +52,11 @@ public class Pylon {
public void apply() {
for (PylonRecipe r : PylonRecipeRegistry.recipes) {
if (r.result.isItemEqual(stack)) {
recipesToRemove.add(r);
recipes.add(r);
}
}
for (PylonRecipe r : recipesToRemove) {
recipesToRemove.remove(r);
}
super.apply();
}
}

View file

@ -59,12 +59,10 @@ public class Apothecary {
public void apply() {
for (RecipePetals r : BotaniaAPI.petalRecipes) {
if (areEqual(r.getOutput(), stack)) {
recipe = r;
break;
recipes.add(r);
}
}
BotaniaAPI.petalRecipes.remove(recipe);
super.apply();
}
@Override

View file

@ -48,12 +48,10 @@ public class ElvenTrade {
public void apply() {
for (RecipeElvenTrade r : BotaniaAPI.elvenTradeRecipes) {
if (r.getOutput() != null && areEqual(r.getOutput(), stack)) {
recipe = r;
break;
recipes.add(r);
}
}
BotaniaAPI.elvenTradeRecipes.remove(recipe);
super.apply();
}
@Override

View file

@ -63,12 +63,10 @@ public class ManaInfusion {
public void apply() {
for (RecipeManaInfusion r : BotaniaAPI.manaInfusionRecipes) {
if (r.getOutput() != null && areEqual(r.getOutput(), stack)) {
recipe = r;
break;
recipes.add(r);
}
}
BotaniaAPI.manaInfusionRecipes.remove(recipe);
super.apply();
}
@Override

View file

@ -48,12 +48,10 @@ public class RuneAltar {
public void apply() {
for (RecipeRuneAltar r : BotaniaAPI.runeAltarRecipes) {
if (r.getOutput() != null && areEqual(r.getOutput(), stack)) {
recipe = r;
break;
recipes.add(r);
}
}
BotaniaAPI.runeAltarRecipes.remove(recipe);
super.apply();
}
@Override

View file

@ -86,13 +86,11 @@ public class ExtendedCrafting {
if (o instanceof IExtendedRecipe) {
IExtendedRecipe r = (IExtendedRecipe) o;
if (r.getRecipeOutput() != null && areEqual((ItemStack) r.getRecipeOutput(), stack)) {
recipe = r;
break;
recipes.add(r);
}
}
}
ExtendedCraftingManager.getInstance().getRecipeList().remove(recipe);
super.apply();
}
@Override

View file

@ -58,13 +58,11 @@ public class Crystallizer {
if (r != null) {
ItemStack output = getOutput(r);
if (output != null && areEqual(output, stack)) {
recipe = r;
break;
recipes.add(r);
}
}
}
list.remove(recipe);
super.apply();
}
@Override

View file

@ -56,12 +56,10 @@ public class Lacerator {
for (Object r : list) {
ItemStack output = getOutput(r);
if (output != null && areEqual(output, stack)) {
recipe = r;
break;
recipes.add(r);
}
}
list.remove(recipe);
super.apply();
}
@Override

View file

@ -75,18 +75,16 @@ public class Carpenter {
public Remove(List list, ItemStack stack) {
super("Forestry Carpenter", list, stack);
}
@Override
public void apply() {
for (Recipe r : RecipeManager.recipes) {
if (r.getCraftingResult() != null && r.getCraftingResult().isItemEqual(stack)) {
recipe = r;
break;
recipes.add(r);
}
}
RecipeManager.recipes.remove(recipe);
super.apply();
}
@Override

View file

@ -63,11 +63,10 @@ public class Centrifuge {
public void apply() {
for (Recipe r : RecipeManager.recipes) {
if (r.matches(stack)) {
recipe = r;
RecipeManager.recipes.remove(r);
break;
recipes.add(r);
}
}
super.apply();
}
@Override

View file

@ -54,16 +54,13 @@ public class Fermenter {
@Override
public void apply() {
ArrayList<Recipe> recipes = new ArrayList<Recipe>();
for (Recipe r : RecipeManager.recipes) {
if (r != null && r.resource != null && r.resource.isItemEqual(stack)) {
recipes.add(r);
}
}
for (Recipe r : recipes) {
RecipeManager.recipes.remove(r);
}
super.apply();
}
}

View file

@ -51,13 +51,10 @@ public class Moistener {
public void apply() {
for (Recipe r : RecipeManager.recipes) {
if (r.product != null && r.product.isItemEqual(stack)) {
recipe = r;
break;
recipes.add(r);
}
}
RecipeManager.recipes.remove(recipe);
super.apply();
}
}
}

View file

@ -57,12 +57,10 @@ public class Squeezer {
public void apply() {
for (Recipe r : RecipeManager.recipes) {
if (r.liquid != null && r.liquid.isFluidEqual(fluid)) {
recipe = r;
break;
recipes.add(r);
}
}
RecipeManager.recipes.remove(recipe);
super.apply();
}
}

View file

@ -56,13 +56,10 @@ public class Still {
public void apply() {
for (Recipe r : RecipeManager.recipes) {
if (r.output != null && r.output.isFluidEqual(fluid)) {
recipe = r;
break;
recipes.add(r);
}
}
RecipeManager.recipes.remove(recipe);
super.apply();
}
}
}

View file

@ -2,6 +2,9 @@ package modtweaker2.mods.forestry.handlers;
import static modtweaker2.helpers.InputHelper.toFluid;
import static modtweaker2.helpers.InputHelper.toStack;
import java.util.List;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IItemStack;
import minetweaker.api.liquid.ILiquidStack;
@ -28,7 +31,7 @@ public class ThermionicFabricator {
@ZenMethod
public static void removeSmelting(IItemStack itemInput) {
MineTweakerAPI.apply(new RemoveSmelting(toStack(itemInput)));
MineTweakerAPI.apply(new Remove(toStack(itemInput), RecipeManager.smeltings, RecipeType.Smelting));
}
//second step: casting liquid + objetcs + plan into result
@ -46,7 +49,7 @@ public class ThermionicFabricator {
@ZenMethod
public static void removeCasts(IItemStack product) {
MineTweakerAPI.apply(new RemoveCastings(toStack(product)));
MineTweakerAPI.apply(new Remove(toStack(product), RecipeManager.recipes, RecipeType.Casting));
}
/*
@ -73,53 +76,54 @@ public class ThermionicFabricator {
}
/*
Implements the actions to remove a smelting recipe
Implements the actions to remove recipes
*/
private static class RemoveSmelting extends BaseListRemoval {
private static class Remove extends BaseListRemoval {
private final RecipeType type;
public RemoveSmelting(ItemStack input) {
super("Forestry Thermionic Fabricator (Smelting)", RecipeManager.smeltings, input);
public Remove(ItemStack input, List list, RecipeType type) {
super(String.format("Forestry Thermionic Fabricator (%s)", type.toString()), RecipeManager.smeltings, input);
this.type = type;
}
@Override
public void apply() {
for (Smelting r : RecipeManager.smeltings) {
if (r.getResource() != null && r.getResource().isItemEqual(stack)) {
RecipeManager.smeltings.remove(r);
recipe = r;
break;
}
}
switch(type) {
case Smelting:
for (Object r : list) {
if (((Smelting)r).getResource() != null && ((Smelting)r).getResource().isItemEqual(stack)) {
recipes.add(r);
}
}
break;
case Casting:
for (Object r : list) {
if (((Recipe)r).asIRecipe().getRecipeOutput() != null && ((Recipe)r).asIRecipe().getRecipeOutput().isItemEqual(stack)) {
recipes.add(r);
}
}
break;
}
super.apply();
}
@Override
public String getRecipeInfo() {
return " Input:" + stack.getDisplayName(); // + " -- Output:" + ((Smelting) recipe).getProduct().getLocalizedName();
switch(type) {
case Smelting:
return " Input:" + stack.getDisplayName(); // + " -- Output:" + ((Smelting) recipe).getProduct().getLocalizedName();
case Casting:
return " Output:" + stack.getDisplayName(); // + " -- Output:" + ((Recipe) recipe).asIRecipe().getIngredients()[0].getDisplayName();
}
return stack.getDisplayName();
}
}
/*
Implements the actions to remove a casting recipe
*/
private static class RemoveCastings extends BaseListRemoval {
public RemoveCastings(ItemStack output) {
super("Forestry Thermionic Fabricator (Casting)", RecipeManager.recipes, output);
}
@Override
public void apply() {
for (Recipe r : RecipeManager.recipes) {
if (r.asIRecipe().getRecipeOutput() != null && r.asIRecipe().getRecipeOutput().isItemEqual(stack)) {
recipe = r;
}
}
RecipeManager.recipes.remove(recipe);
}
@Override
public String getRecipeInfo() {
return " Output:" + stack.getDisplayName(); // + " -- Output:" + ((Recipe) recipe).asIRecipe().getIngredients()[0].getDisplayName();
}
}
public enum RecipeType {
Smelting,
Casting
}
}

View file

@ -62,17 +62,14 @@ public class Crucible {
// recipe then removes it
@Override
public void apply() {
for (RecipeSmelter r : MaricultureHandlers.crucible.getRecipes()) {
if (r != null) {
if (r.input != null && stack != null && areEqual(r.input, stack)) {
recipe = r;
break;
recipes.add(r);
}
}
}
if (recipe != null)
MaricultureHandlers.crucible.getRecipes().remove(recipe);
super.apply();
}
@Override

View file

@ -115,18 +115,18 @@ public class Vat {
if (r != null)
if (r.outputItem != null && stack != null && areEqual(r.outputItem, stack)) {
if (r.outputFluid == null || (fluid != null && r.outputFluid.isFluidStackIdentical(fluid))) {
recipe = r;
recipes.add(r);
break;
}
}
if ((r.outputFluid != null && fluid != null && r.outputFluid.isFluidStackIdentical(fluid))) {
recipe = r;
recipes.add(r);
break;
}
}
if (recipe != null)
MaricultureHandlers.vat.getRecipes().remove(recipe);
super.apply();
}
@Override

View file

@ -52,12 +52,10 @@ public class Alloyer {
public void apply() {
for (AlloyRecipe r : MetallurgyHelper.alloyerRecipes) {
if (r.getCraftingResult() != null && areEqual(r.getCraftingResult(), stack)) {
recipe = r;
break;
recipes.add(r);
}
}
MetallurgyHelper.alloyerRecipes.remove(recipe);
super.apply();
}
@Override

View file

@ -68,12 +68,11 @@ public class Assembly {
public void apply() {
for (AssemblyRecipe r : (List<AssemblyRecipe>) list) {
if (r.getOutput() != null && areEqual(r.getOutput(), stack)) {
recipe = r;
break;
recipes.add(r);
}
}
list.remove(recipe);
super.apply();
}
@Override

View file

@ -52,19 +52,17 @@ public class Pressure {
for (PressureChamberRecipe r : PressureChamberRecipe.chamberRecipes) {
boolean matches = true;
for (int i = 0; i < stacks.length; i++) {
if (!areEqual(stacks[i], r.output[i])) {
if (!areEqual(stacks[i], r.output[i])) { // possible IndexOutOfBoundsException on r.output[i]
matches = false;
break;
}
}
if (matches) {
recipe = r;
break;
recipes.add(r);
}
}
PressureChamberRecipe.chamberRecipes.remove(recipe);
super.apply();
}
@Override

View file

@ -46,14 +46,12 @@ public class BlastFurnace {
@Override
public void apply() {
ArrayList<IBlastFurnaceRecipe> recipesToRemove = new ArrayList<IBlastFurnaceRecipe>();
for (IBlastFurnaceRecipe r : RailcraftHelper.furnace) {
if (r.getOutput() != null && stack.isItemEqual(r.getOutput())) {
recipesToRemove.add(r);
recipes.add(r);
}
}
for (IBlastFurnaceRecipe r : recipesToRemove)
RailcraftCraftingManager.blastFurnace.getRecipes().remove(r);
super.apply();
}
@Override

View file

@ -93,12 +93,10 @@ public class CokeOven {
public void apply() {
for (ICokeOvenRecipe r : RailcraftHelper.oven) {
if (r.getOutput() != null && r.getOutput().getItem().equals(stack)) {
recipe = r;
break;
recipes.add(r);
}
}
RailcraftHelper.oven.remove(recipe);
super.apply();
}
@Override

View file

@ -49,12 +49,10 @@ public class RockCrusher {
public void apply() {
for (IRockCrusherRecipe r : RailcraftHelper.crusher) {
if (r.getInput() != null && areEqual(r.getInput(), stack)) {
recipe = r;
break;
recipes.add(r);
}
}
RailcraftHelper.crusher.remove(recipe);
super.apply();
}
@Override

View file

@ -76,18 +76,15 @@ public class Casting {
// Removes all matching recipes, apply is never the same for anything, so will always need to override it
private static class Remove extends BaseListRemoval {
protected final LinkedList<CastingRecipe> removedRecipes;
protected final RecipeComponent component;
public Remove(ItemStack item, ArrayList list, RecipeComponent component) {
super("TConstruct Casting", list, item);
this.removedRecipes = new LinkedList<CastingRecipe>();
this.component = component;
}
public Remove(FluidStack fluid, ArrayList list) {
super("TConstruct Casting", list, fluid);
this.removedRecipes = new LinkedList<CastingRecipe>();
this.component = RecipeComponent.Material;
}
@ -96,45 +93,32 @@ public class Casting {
public void apply() {
for (Iterator<CastingRecipe> iterator = ((ArrayList<CastingRecipe>)list).iterator(); iterator.hasNext();) {
CastingRecipe r = iterator.next();
boolean removeRecipie = false;
switch(component)
{
case Cast:
if (r.cast != null && areEqual(r.cast, stack)) {
removeRecipie = true;
recipes.add(r);
}
break;
case Material:
if (r.castingMetal != null && r.castingMetal.isFluidEqual(fluid)) {
removeRecipie = true;
recipes.add(r);
}
break;
case Output:
if (r.output != null && areEqual(r.output, stack)) {
removeRecipie = true;
recipes.add(r);
}
break;
}
if(removeRecipie) {
iterator.remove();
removedRecipes.add(r);
}
}
}
@Override
public void undo() {
for(CastingRecipe recipe : removedRecipes) {
this.list.add(recipe);
}
removedRecipes.clear();
super.apply();
}
@Override

View file

@ -55,12 +55,10 @@ public class Drying {
public void apply() {
for (DryingRecipe r : (ArrayList<DryingRecipe>) list) {
if (r.result != null && areEqual(r.result, stack)) {
recipe = r;
break;
recipes.add(r);
}
}
list.remove(recipe);
super.apply();
}
@Override

View file

@ -29,12 +29,10 @@ public class Modifiers {
public void apply() {
for (ItemModifier m : (List<ItemModifier>) list) {
if (m.key.equals(check)) {
recipe = m;
break;
recipes. add(m);
}
}
list.remove(recipe);
super.apply();
}
}
}

View file

@ -72,13 +72,10 @@ public class Smeltery {
public void apply() {
for (AlloyMix r : TConstructHelper.alloys) {
if (r.result != null && fluid != null && r.result.getFluid() == fluid.getFluid()) {
recipe = r;
break;
recipes.add(r);
}
}
if (recipe != null)
TConstructHelper.alloys.remove(recipe);
super.apply();
}
@Override

View file

@ -98,13 +98,11 @@ public class TiCTweaks {
ItemStack clone = new ItemStack(r.item, 1, r.damage);
if ((material != null && material.equalsIgnoreCase(r.key)) || (material == null)) {
if (clone.isItemEqual(stack)) {
recipe = r;
break;
recipes.add(r);
}
}
}
PatternBuilder.instance.materials.remove(recipe);
super.apply();
}
@Override

View file

@ -65,15 +65,12 @@ public class Anvil {
@Override
public void apply() {
ArrayList<AnvilRecipe> toRemove = new ArrayList<AnvilRecipe>();
for (AnvilRecipe recipe : AnvilManager.getInstance().getRecipeList()){
if (recipe.getCraftingResult() != null && areEqual(recipe.getCraftingResult(), stack)){
toRemove.add(recipe);
recipes.add(recipe);
}
}
for (AnvilRecipe aRecipe : toRemove){
TFCHelper.anvilRecipes.remove(aRecipe);
}
super.apply();
}
}
@ -84,16 +81,12 @@ public class Anvil {
@Override
public void apply() {
ArrayList<AnvilRecipe> toRemove = new ArrayList<AnvilRecipe>();
for (AnvilRecipe recipe : AnvilManager.getInstance().getRecipeList()){
if (recipe.getCraftingResult() != null && recipe.getCraftingResult() == stack){
toRemove.add(recipe);
recipes.add(recipe);
}
}
for (AnvilRecipe aRecipe : toRemove){
TFCHelper.anvilWeldRecipes.remove(aRecipe);
}
super.apply();
}
}
}

View file

@ -80,20 +80,17 @@ public class Barrel {
@Override
public void apply() {
ArrayList<BarrelRecipe> toRemove = new ArrayList<BarrelRecipe>();
for (BarrelRecipe recipe : BarrelManager.getInstance().getRecipes()){
if (recipe.getRecipeOutIS() != null && areEqual(recipe.getRecipeOutIS(), stack)){
toRemove.add(recipe);
recipes.add(recipe);
}
}
for (BarrelRecipe recipe : BarrelManager.getInstance().getRecipes()){
if (recipe.getRecipeOutFluid() != null && recipe.getRecipeOutFluid().isFluidEqual(fluid)){
toRemove.add(recipe);
recipes.add(recipe);
}
}
for (BarrelRecipe aRecipe : toRemove){
TFCHelper.barrelRecipes.remove(aRecipe);
}
super.apply();
}
}
}

View file

@ -45,17 +45,14 @@ public class Kiln {
super("Kiln-Remove", TFCHelper.kilnRecipes, out);
}
@Override
@Override
public void apply() {
ArrayList<KilnRecipe> toRemove = new ArrayList<KilnRecipe>();
for (KilnRecipe recipe : KilnCraftingManager.getInstance().getRecipeList()){
if (recipe.getCraftingResult() != null && areEqual(recipe.getCraftingResult(), stack)){
toRemove.add(recipe);
recipes.add(recipe);
}
}
for (KilnRecipe aRecipe : toRemove){
TFCHelper.kilnRecipes.remove(aRecipe);
}
super.apply();
}
}

View file

@ -44,17 +44,27 @@ public class Quern {
@Override
public void apply() {
ArrayList<QuernRecipe> toRemove = new ArrayList<QuernRecipe>();
for (QuernRecipe recipe : QuernManager.getInstance().getRecipes()){
if (recipe.getResult() !=null && areEqual(recipe.getResult(), stack)){
toRemove.add(recipe);
recipes.add(recipe);
}
}
for (QuernRecipe aRecipe : toRemove){
TFCHelper.quernRecipes.remove(aRecipe);
TFCHelper.quernVaildItems.remove(aRecipe.getInItem());
for (Object aRecipe : recipes){
TFCHelper.quernVaildItems.remove(((QuernRecipe)aRecipe).getInItem());
}
super.apply();
}
@Override
public void undo() {
for (Object aRecipe : recipes){
TFCHelper.quernVaildItems.add(((QuernRecipe)aRecipe).getInItem());
}
super.undo();
}
}
}

View file

@ -65,19 +65,15 @@ public class Arcane {
@Override
public void apply() {
ArrayList<IArcaneRecipe> recipesToRemove = new ArrayList<IArcaneRecipe>();
for (Object o : ThaumcraftApi.getCraftingRecipes()) {
if (o != null && o instanceof IArcaneRecipe) {
IArcaneRecipe r = (IArcaneRecipe) o;
if (r.getRecipeOutput() != null && r.getRecipeOutput().isItemEqual(stack)) {
recipesToRemove.add(r);
recipes.add(r);
}
}
}
for (IArcaneRecipe r : recipesToRemove) {
ThaumcraftApi.getCraftingRecipes().remove(r);
}
super.apply();
}
@Override

View file

@ -54,13 +54,11 @@ public class Crucible {
if (o instanceof CrucibleRecipe) {
CrucibleRecipe r = (CrucibleRecipe) o;
if (r.getRecipeOutput() != null && areEqual(r.getRecipeOutput(), stack)) {
recipe = r;
break;
recipes.add(r);
}
}
}
ThaumcraftApi.getCraftingRecipes().remove(recipe);
super.apply();
}
@Override

View file

@ -119,13 +119,11 @@ public class Infusion {
if (o instanceof InfusionRecipe) {
InfusionRecipe r = (InfusionRecipe) o;
if (r.getRecipeOutput() != null && r.getRecipeOutput() instanceof ItemStack && areEqual((ItemStack) r.getRecipeOutput(), stack)) {
recipe = r;
break;
recipes.add(r);
}
}
}
ThaumcraftApi.getCraftingRecipes().remove(recipe);
super.apply();
}
@Override
@ -134,50 +132,30 @@ public class Infusion {
}
}
private static class RemoveEnchant implements IUndoableAction {
private static class RemoveEnchant extends BaseListRemoval {
Enchantment enchant;
InfusionEnchantmentRecipe removed;
public RemoveEnchant(Enchantment ench) {
super("Thaumcraft Infusion Enchantment", ThaumcraftApi.getCraftingRecipes());
enchant = ench;
}
@Override
public void apply() {
for (Object recipe : ThaumcraftApi.getCraftingRecipes()) {
for (Object recipe : list) {
if (recipe instanceof InfusionEnchantmentRecipe) {
InfusionEnchantmentRecipe enchRecipe = (InfusionEnchantmentRecipe) recipe;
if (enchRecipe.getEnchantment() == enchant) {
removed = enchRecipe;
ThaumcraftApi.getCraftingRecipes().remove(enchRecipe);
recipes.add(enchRecipe);
}
}
}
super.apply();
}
@Override
public String describe() {
return "Removing Infusion Enchantment Recipe: " + enchant.getName();
}
@Override
public boolean canUndo() {
return removed != null;
}
@Override
public void undo() {
ThaumcraftApi.getCraftingRecipes().add(removed);
}
@Override
public String describeUndo() {
return "Restoring Infusion Enchantment Recipe: " + enchant.getName();
}
@Override
public String getOverrideKey() {
return null;
}
@Override
public String getRecipeInfo() {
return enchant.getName();
}
}
}

View file

@ -53,23 +53,18 @@ public class Loot {
}
public static class Remove extends BaseListRemoval {
public Remove(List list, ItemStack stack) {
super(list, stack);
}
@Override
public void apply() {
List<WeightedRandomLoot> loot = (List<WeightedRandomLoot>) list;
WeightedRandomLoot remove = null;
for (WeightedRandomLoot stack : loot) {
for (WeightedRandomLoot stack : (List<WeightedRandomLoot>) list) {
if (stack.item.isItemEqual(this.stack)) {
remove = stack;
break;
recipes.add(stack);
}
}
loot.remove(remove);
super.apply();
}
}
}

View file

@ -16,12 +16,10 @@ public class BaseCraftingRemoval extends BaseListRemoval {
public void apply() {
for (IRecipe r : (List<IRecipe>) list) {
if (r.getRecipeOutput() != null && r.getRecipeOutput() instanceof ItemStack && areEqual(r.getRecipeOutput(), stack)) {
recipe = r;
break;
recipes.add(r);
}
}
list.remove(recipe);
super.apply();
}
@Override

View file

@ -1,9 +1,12 @@
package modtweaker2.utils;
import minetweaker.IUndoableAction;
import minetweaker.MineTweakerAPI;
import modtweaker2.helpers.LogHelper;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import java.util.LinkedList;
import java.util.List;
public abstract class BaseListRemoval implements IUndoableAction {
@ -12,7 +15,7 @@ public abstract class BaseListRemoval implements IUndoableAction {
protected final FluidStack fluid;
protected final ItemStack stack;
protected Object recipe;
protected final LinkedList recipes = new LinkedList();
public BaseListRemoval(String description, List list, ItemStack stack, FluidStack fluid) {
this.list = list;
@ -40,16 +43,29 @@ public abstract class BaseListRemoval implements IUndoableAction {
public BaseListRemoval(String description, List list) {
this(description, list, null, null);
}
@Override
public void apply() {
if(recipes.size() == 0) {
MineTweakerAPI.logWarning(String.format("No %s Recipes to remove for: %s", this.description, getRecipeInfo()));
return;
}
for(Object recipe : recipes) {
list.remove(recipe);
}
}
@Override
public boolean canUndo() {
return list != null;
return recipes.size() > 0;
}
@Override
public void undo() {
list.add(recipe);
for(Object recipe : recipes) {
list.add(recipe);
}
}
public String getRecipeInfo() {
@ -58,24 +74,60 @@ public abstract class BaseListRemoval implements IUndoableAction {
@Override
public String describe() {
if (recipe instanceof ItemStack)
return "Removing " + description + " Recipe for :" + ((ItemStack) recipe).getDisplayName();
else if (recipe instanceof FluidStack)
return "Removing " + description + " Recipe for :" + ((FluidStack) recipe).getFluid().getLocalizedName();
else return "Removing " + description + " Recipe for :" + getRecipeInfo();
if(recipes.size() > 0) {
return String.format("Removing %d %s Recipe(s) for: %s", recipes.size(), this.description, getRecipeNames(recipes));
} else {
return String.format("Removing %s Recipe(s) for: %s", this.description, getRecipeInfo());
}
}
@Override
public String describeUndo() {
if (recipe instanceof ItemStack)
return "Restoring " + description + " Recipe for :" + ((ItemStack) recipe).getDisplayName();
else if (recipe instanceof FluidStack)
return "Restoring " + description + " Recipe for :" + ((FluidStack) recipe).getFluid().getLocalizedName();
else return "Restoring " + description + " Recipe for :" + getRecipeInfo();
if(recipes.size() > 0) {
return String.format("Restoring %d %s Recipe(s) for: %s", recipes.size(), this.description, getRecipeNames(recipes));
} else {
return String.format("No %s Recipes found to restore for: %s", this.description, getRecipeInfo());
}
}
@Override
public Object getOverrideKey() {
return null;
}
/***
* Returns the names of the recipes inside the list
* @param list which holds the recipes
* @return name or list of names describing the recipe
*/
private String getRecipeNames(LinkedList list) {
if(list.size() == 0)
return getRecipeInfo();
if(list.size() == 1) {
if(recipes.getFirst() instanceof ItemStack)
return ((ItemStack)list.getFirst()).getDisplayName();
else if (recipes.getFirst() instanceof FluidStack)
return ((FluidStack)list.getFirst()).getFluid().getLocalizedName();
else
return getRecipeInfo();
}
StringBuilder sb = new StringBuilder();
if(recipes.getFirst() instanceof ItemStack) {
for(ItemStack itemStack : (List<ItemStack>)list) {
sb.append(itemStack.getDisplayName()).append(", ");
}
} else if (recipes.getFirst() instanceof FluidStack) {
for(FluidStack fluidStack : (List<FluidStack>)list) {
sb.append(fluidStack.getFluid().getLocalizedName()).append(", ");
}
} else {
sb.append(getRecipeInfo()).append(", ");
}
sb.setLength(sb.length() - 2);
return sb.toString();
}
}