package tehnut.resourceful.crops.compat.enderio;

import crazypants.enderio.machine.farm.TileFarmStation;
import crazypants.enderio.machine.farm.farmers.HarvestResult;
import crazypants.enderio.machine.farm.farmers.IHarvestResult;
import crazypants.enderio.machine.farm.farmers.PlantableFarmer;
import crazypants.util.BlockCoord;
import net.minecraft.block.Block;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import tehnut.resourceful.crops.blocks.BlockRCrop;
import tehnut.resourceful.crops.items.ItemSeed;

import java.util.ArrayList;
import java.util.List;

public class ResourcefulCropsFarmer extends PlantableFarmer {

    @Override
    public boolean canHarvest(TileFarmStation farmStation, BlockCoord coord, Block block, int meta) {
        return block instanceof BlockRCrop && farmStation.getWorldObj().getBlockMetadata(coord.x, coord.y, coord.z) == 7;
    }

    @Override
    public boolean canPlant(ItemStack stack) {
        return stack != null && stack.getItem() instanceof ItemSeed;
    }

    @Override
    public boolean prepareBlock(TileFarmStation farmStation, BlockCoord coord, Block block, int meta) {
        if (block == null)
            return false;

        ItemStack seedStack = farmStation.getSeedTypeInSuppliesFor(coord);
        if (seedStack == null) {
            farmStation.setNotification("noSeeds");
            return false;
        }

        if (!canPlant(seedStack))
            return false;

        Item seed = seedStack.getItem();

        if (seed.onItemUse(seedStack, farmStation.getFakePlayer(), farmStation.getWorldObj(), coord.x, coord.y - 1, coord.z, 1, 0.5F, 0.5F, 0.5F))
            farmStation.takeSeedFromSupplies(coord);

        return false;
    }

    @Override
    public IHarvestResult harvestBlock(TileFarmStation farmStation, BlockCoord coord, Block block, int meta) {
        if (!canHarvest(farmStation, coord, block, meta) || !farmStation.hasHoe() || !(block instanceof BlockRCrop))
            return null;

        List<ItemStack> dropped = ((BlockRCrop)block).getDrops(farmStation.getWorldObj(), coord.x, coord.y, coord.z, meta);
        farmStation.getWorldObj().setBlockMetadataWithNotify(coord.x, coord.y, coord.z, 0, 3);
        return new HarvestResult(getEntities(farmStation.getWorldObj(), coord, dropped), coord);
    }

    private List<EntityItem> getEntities(World world, BlockCoord bc,  List<ItemStack> dropped) {
        List<EntityItem> entities = new ArrayList<EntityItem>(dropped.size());
        for (ItemStack stack : dropped)
            entities.add(new EntityItem(world, bc.x + 0.5, bc.y + 0.2, bc.z + 0.5, stack));

        return entities;
    }
}

@@ -1383,62 +1383,8 @@
 ull)
- %7B%0A            farmStation.setNotification(%22noSeeds%22);
 %0A   
@@ -1409,18 +1409,8 @@
 lse;
-%0A        %7D
 %0A%0A  
@@ -2132,16 +2132,57 @@
  meta);%0A
+        BlockRCrop.setShouldDrop(false);%0A
         
@@ -2219,26 +2219,13 @@
 lock
-MetadataWithNotify
+ToAir
 (coo
@@ -2250,14 +2250,48 @@
 rd.z
-, 0, 3
+);%0A        BlockRCrop.setShouldDrop(true
 );%0A 

Fix seed dupe in EnderIO Compat