package mariculture.plugins;

import static mariculture.core.helpers.RecipeHelper.addShapeless;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;

import mariculture.api.fishery.Fishing;
import mariculture.api.fishery.RodType;
import mariculture.api.fishery.fish.FishSpecies;
import mariculture.core.Core;
import mariculture.core.lib.MaterialsMeta;
import mariculture.core.lib.Modules;
import mariculture.plugins.Plugins.Plugin;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import rebelkeithy.mods.aquaculture.items.AquacultureItems;

public class PluginAquaculture extends Plugin {
    public PluginAquaculture(String name) {
        super(name);
    }

    @Override
    public void preInit() {
        return;
    }

    @Override
    public void init() {
        if (Modules.isActive(Modules.fishery)) {
            Fishing.fishing.addBait(new ItemStack(AquacultureItems.fish, 1, 19), 25);
            Fishing.fishing.addBaitForQuality(new ItemStack(AquacultureItems.fish, 1, 19), Arrays.asList(RodType.DIRE, RodType.FLUX));
        }
    }

    @Override
    public void postInit() {
        if (Modules.isActive(Modules.fishery)) {
            //Remove Fish Fillet Recipes, We readd them later with a new recipe
            remove(getItem("item.loot"), 3);

            for (Entry<Integer, FishSpecies> list : FishSpecies.species.entrySet()) {
                FishSpecies species = list.getValue();
                if (species.getFishMealSize() > 0) {
                    addShapeless(new ItemStack(getItem("item.loot"), species.getFishMealSize(), 3), new Object[] { species.getRawForm(1), "foodSalt" });
                }
            }
        }
    }

    public void remove(Item item, int meta) {
        List<ItemStack> list = new ArrayList();
        for (Iterator<IRecipe> iterator = CraftingManager.getInstance().getRecipeList().iterator(); iterator.hasNext();) {
            IRecipe recipe = iterator.next();
            if (recipe.getRecipeOutput() != null) {
                if (recipe.getRecipeOutput().getItem() == item && recipe.getRecipeOutput().getItemDamage() == meta) {
                    list.add(recipe.getRecipeOutput().copy());
                    iterator.remove();
                }
            }
        }

        for (ItemStack output : list) {
            for (int i = 0; i < AquacultureItems.fish.fish.size(); i++) {
                if ((i >= 14 && i <= 19) || i == 38) continue;
                addShapeless(output, new Object[] { new ItemStack(AquacultureItems.fish, 1, i), "foodSalt" });
                addShapeless(new ItemStack(Core.materials, output.stackSize, MaterialsMeta.FISH_MEAL), new Object[] { new ItemStack(AquacultureItems.fish, 1, i) });
            }
        }
    }
}

@@ -94,36 +94,8 @@
 s;%0A%0A
-import java.util.ArrayList;%0A
 impo
@@ -146,31 +146,8 @@
 or;%0A
-import java.util.List;%0A
 impo
@@ -677,16 +677,73 @@
 reItems;
+%0Aimport rebelkeithy.mods.aquaculture.items.ItemFish.Fish;
 %0A%0Apublic
@@ -1845,32 +1845,546 @@
      %7D%0A        %7D
+%0A%0A        for (int i = 0; i %3C AquacultureItems.fish.fish.size(); i++) %7B%0A            Fish f = AquacultureItems.fish.fish.get(i);%0A            if (f.filletAmount != 0) %7B%0A                addShapeless(AquacultureItems.fishFillet.getItemStack(f.filletAmount), new Object%5B%5D %7B new ItemStack(AquacultureItems.fish, 1, i), %22foodSalt%22 %7D);%0A                addShapeless(new ItemStack(Core.materials, f.filletAmount, MaterialsMeta.FISH_MEAL), new Object%5B%5D %7B new ItemStack(AquacultureItems.fish, 1, i) %7D);%0A            %7D%0A        %7D
 %0A    %7D%0A%0A    publ
@@ -2425,56 +2425,8 @@
 ) %7B%0A
-        List%3CItemStack%3E list = new ArrayList();%0A
     
@@ -2784,585 +2784,44 @@
     
-list.add(recipe.getRecipeOutput().copy());%0A                    iterator.remove();%0A                %7D%0A            %7D%0A        %7D%0A%0A        for (ItemStack output : list) %7B%0A            for (int i = 0; i %3C AquacultureItems.fish.fish.size(); i++) %7B%0A                if ((i %3E= 14 && i %3C= 19) %7C%7C i == 38) continue;%0A                addShapeless(output, new Object%5B%5D %7B new ItemStack(AquacultureItems.fish, 1, i), %22foodSalt%22 %7D);%0A                addShapeless(new ItemStack(Core.materials, output.stackSize, MaterialsMeta.FISH_MEAL), new Object%5B%5D %7B new ItemStack(AquacultureItems.fish, 1, i) %7D);
+iterator.remove();%0A                %7D
 %0A   

Fix fillet recipes