package tehnut.resourceful.crops.compat.bloodmagic;

import WayofTime.bloodmagic.api.BlockStack;
import WayofTime.bloodmagic.api.iface.IHarvestHandler;
import net.minecraft.block.Block;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import tehnut.lib.util.helper.BlockHelper;
import tehnut.lib.util.helper.ItemHelper;
import tehnut.resourceful.crops.api.ResourcefulAPI;
import tehnut.resourceful.crops.block.BlockRCrop;
import tehnut.resourceful.crops.item.ItemShard;
import tehnut.resourceful.crops.tile.TileRCrop;

public class ResourcefulCropsHarvestHandler implements IHarvestHandler {

    @Override
    public boolean harvestAndPlant(World world, BlockPos blockPos, BlockStack blockStack) {
        if (blockStack.getBlock() instanceof BlockRCrop && blockStack.getMeta() >= 7) {
            TileEntity tile = world.getTileEntity(blockPos);
            if (tile != null && tile instanceof TileRCrop) {
                TileRCrop tileCrop = (TileRCrop) tile;
                BlockStack newBlock = new BlockStack(BlockHelper.getBlock(BlockRCrop.class));
                world.setBlockState(blockPos, newBlock.getState());
                world.destroyBlock(blockPos, false);
                ItemStack drop = new ItemStack(ItemHelper.getItem(ItemShard.class), 1, ResourcefulAPI.SEEDS.getId(tileCrop.getSeedName()));
                dropItem(world, blockPos, drop);
                return true;
            }
        }

        return false;
    }

    private void dropItem(World world, BlockPos pos, ItemStack stack) {
        if (!world.isRemote && !world.restoringBlockSnapshots) {
            float f = 0.7F;
            double xOff = (double) (world.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
            double yOff = (double) (world.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
            double zOff = (double) (world.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
            EntityItem entityitem = new EntityItem(world, (double) pos.getX() + xOff, (double) pos.getY() + yOff, (double) pos.getZ() + zOff, stack);
            entityitem.setPickupDelay(10);
            world.spawnEntityInWorld(entityitem);
        }
    }
}

@@ -1229,38 +1229,59 @@
 rld.
-set
+playEvent(2001, blockPos, 
 Block
+.get
 State
+Id
 (block
-Pos, newBlo
+Sta
 ck.g
@@ -1290,16 +1290,17 @@
 State())
+)
 ;%0A      
@@ -1319,36 +1319,51 @@
 rld.
-destroyBlock(blockPos, false
+setBlockState(blockPos, newBlock.getState()
 );%0A 

Fix Blood Magic integration