package wanion.unidict.integration;

import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.recipe.CrusherRecipe;

import java.lang.reflect.Field;

public class ActuallyAdditionsIntegration extends AbstractIntegrationThread {
    private Field crusherOutputOne;
    private Field crusherOutputTwo;

    public ActuallyAdditionsIntegration() {
        super("Actually Additions");
        try {
            crusherOutputOne = CrusherRecipe.class.getDeclaredField("outputOne");
            crusherOutputOne.setAccessible(true);
            crusherOutputTwo = CrusherRecipe.class.getDeclaredField("outputTwo");
            crusherOutputTwo.setAccessible(true);
        } catch (NoSuchFieldException e) {
            logger.error("Could not find actually additions fields!");
            e.printStackTrace();
        }
    }

    @Override
    public String call() {
        try {
            fixCrusherRecipes();
        } catch (Exception e) { logger.error(threadName + e); }
        return threadName + "Actually unified the Additions!";
    }

    private void fixCrusherRecipes() {
        ActuallyAdditionsAPI.CRUSHER_RECIPES.forEach(recipe -> {
            if (crusherOutputOne != null && recipe.getOutputOne() != null) {
                try {
                    crusherOutputOne.set(recipe, resourceHandler.getMainItemStack(recipe.getOutputOne()));
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }

            if (crusherOutputTwo != null && recipe.getOutputTwo() != null){
                try {
                    crusherOutputTwo.set(recipe, resourceHandler.getMainItemStack(recipe.getOutputTwo()));
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        });
    }
}

@@ -153,16 +153,80 @@
 rRecipe;
+%0Aimport de.ellpeck.actuallyadditions.api.recipe.EmpowererRecipe;
 %0A%0Aimport
@@ -401,16 +401,51 @@
 tputTwo;
+%0A    private Field empowererOutput;
 %0A%0A    pu
@@ -789,32 +789,161 @@
 cessible(true);%0A
+            empowererOutput = EmpowererRecipe.class.getDeclaredField(%22output%22);%0A            empowererOutput.setAccessible(true);%0A
         %7D catch 
@@ -1174,24 +1174,59 @@
 rRecipes();%0A
+            fixEmpowererRecipes();%0A
         %7D ca
@@ -1874,32 +1874,32 @@
           try %7B%0A
-
                 
@@ -2132,11 +2132,460 @@
 );%0A    %7D
+%0A%0A    private void fixEmpowererRecipes()%7B%0A        ActuallyAdditionsAPI.EMPOWERER_RECIPES.forEach(recipe -%3E %7B%0A            if (empowererOutput != null && recipe.getOutput() != null)%7B%0A                try %7B%0A                    empowererOutput.set(recipe, resourceHandler.getMainItemStack(recipe.getOutput()));%0A                %7D catch (IllegalAccessException e) %7B%0A                    e.printStackTrace();%0A                %7D%0A            %7D%0A        %7D);%0A    %7D
 %0A%7D%0A

Add support for Actually Additions empowerer