package com.InfinityRaider.AgriCraft.compatibility.applecore;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.world.World;
import squeek.applecore.api.AppleCoreAPI;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.common.eventhandler.Event;

public class AppleCoreHelper {
    public static final String MODID = "AppleCore";
    public static final boolean isAppleCoreLoaded = Loader.isModLoaded(AppleCoreHelper.MODID);
    public static boolean hasDispatcher;
    static {
        try {
            hasDispatcher = isAppleCoreLoaded && Class.forName("squeek.applecore.api.IAppleCoreDispatcher") != null;
        } catch (ClassNotFoundException e) {
            hasDispatcher = false;
        }
    }

    @Optional.Method(modid = AppleCoreHelper.MODID)
    private static Event.Result validateAppleCoreGrowthTick(Block block, World world, int x, int y, int z, Random random) {
        return AppleCoreAPI.dispatcher.validatePlantGrowth(block, world, x, y, z, random);
    }

    @Optional.Method(modid = AppleCoreHelper.MODID)
    private static void announceAppleCoreGrowthTick(Block block, World world, int x, int y, int z) {
        AppleCoreAPI.dispatcher.announcePlantGrowth(block, world, x, y, z);
    }

    public static Event.Result validateGrowthTick(Block block, World world, int x, int y, int z, Random random) {
        if (hasDispatcher)
            return validateAppleCoreGrowthTick(block, world, x, y, z, random);
        else
            return Event.Result.DEFAULT;
    }

    public static void announceGrowthTick(Block block, World world, int x, int y, int z) {
        if (hasDispatcher) {
            announceAppleCoreGrowthTick(block, world, x, y, z);
        }
    }
}

@@ -690,17 +690,16 @@
  %7D catch
- 
 (ClassNo
@@ -715,24 +715,24 @@
 eption e) %7B%0A
+
             
@@ -955,22 +955,124 @@
         
-return
+Event.Result result = Event.Result.DEFAULT;%0A        if(AppleCoreAPI.dispatcher!=null) %7B%0A            result =
  AppleCo
@@ -1136,24 +1136,57 @@
 z, random);%0A
+        %7D%0A        return result;%0A
     %7D%0A%0A    @
@@ -1325,32 +1325,80 @@
 int y, int z) %7B%0A
+        if(AppleCoreAPI.dispatcher!=null) %7B%0A    
         AppleCor
@@ -1453,24 +1453,34 @@
 , x, y, z);%0A
+        %7D%0A
     %7D%0A%0A    p

Fix NPE when AppleCore is installed, but Hunger Overhaul is not