Program: 27572
Project: 27572
Buggy source:
/** 
 * @author gabizou - June 21st, 2016
 * @reason Rewrites the forge handling of this to properly handlewhen sheared drops are captured by whatever current phase the {@link CauseTracker} is in.Returns true if the item can be used on the given entity, e.g. shears on sheep.
 */
@Overwrite @Override public boolean itemInteractionForEntity(ItemStack itemstack,EntityPlayer player,EntityLivingBase entity,EnumHand hand){
  if (entity.worldObj.isRemote) {
    return false;
  }
  if (entity instanceof IShearable) {
    IShearable target=(IShearable)entity;
    BlockPos pos=new BlockPos(entity.posX,entity.posY,entity.posZ);
    if (target.isShearable(itemstack,entity.worldObj,pos)) {
      List<ItemStack> drops=target.onSheared(itemstack,entity.worldObj,pos,EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE,itemstack));
      final CauseTracker causeTracker=((IMixinWorldServer)entity.worldObj).getCauseTracker();
      final PhaseData currentData=causeTracker.getStack().peek();
      final IPhaseState currentState=currentData.state;
      final PhaseContext phaseContext=currentData.context;
      final Random random=EntityUtil.fromNative(entity).getRandom();
      final IMixinEntity mixinEntity=EntityUtil.toMixin(entity);
      final double posX=entity.posX;
      final double posY=entity.posY + 1.0F;
      final double posZ=entity.posZ;
      final Vector3d position=new Vector3d(posX,posY,posZ);
      for (      ItemStack drop : drops) {
        final ItemStack item;
        if (drop.getItem() != null) {
          final ItemStackSnapshot snapshot=ItemStackUtil.createSnapshot(drop);
          final List<ItemStackSnapshot> original=new ArrayList<>();
          original.add(snapshot);
          final DropItemEvent.Pre dropEvent=SpongeEventFactory.createDropItemEventPre(Cause.of(NamedCause.source(entity)),ImmutableList.of(snapshot),original);
          if (dropEvent.isCancelled()) {
            continue;
          }
          Transform<World> suggested=new Transform<>(mixinEntity.getWorld(),position);
          SpawnCause cause=EntitySpawnCause.builder().entity(mixinEntity).type(SpawnTypes.DROPPED_ITEM).build();
          ConstructEntityEvent.Pre event=SpongeEventFactory.createConstructEntityEventPre(Cause.of(NamedCause.source(cause)),EntityTypes.ITEM,suggested);
          SpongeImpl.postEvent(event);
          item=event.isCancelled() ? null : ItemStackUtil.fromSnapshotToNative(dropEvent.getDroppedItems().get(0));
        }
 else {
          continue;
        }
        if (item == null) {
          continue;
        }
        if (item.stackSize != 0 && item.getItem() != null) {
          if (!currentState.getPhase().ignoresItemPreMerging(currentState) && SpongeImpl.getGlobalConfig().getConfig().getOptimizations().doDropsPreMergeItemDrops()) {
            if (currentState.tracksEntitySpecificDrops()) {
              final Multimap<UUID,ItemDropData> multimap=phaseContext.getCapturedEntityDropSupplier().get();
              final Collection<ItemDropData> itemStacks=multimap.get(entity.getUniqueID());
              SpongeImplHooks.addItemStackToListForSpawning(itemStacks,ItemDropData.item(item).motion(new Vector3d((random.nextFloat() - random.nextFloat()) * 0.1F,random.nextFloat() * 0.05F,(random.nextFloat() - random.nextFloat()) * 0.1F)).position(new Vector3d(posX,posY,posZ)).build());
              continue;
            }
 else {
              final List<ItemDropData> itemStacks=phaseContext.getCapturedItemStackSupplier().get();
              SpongeImplHooks.addItemStackToListForSpawning(itemStacks,ItemDropData.item(item).position(new Vector3d(posX,posY,posZ)).motion(new Vector3d((random.nextFloat() - random.nextFloat()) * 0.1F,random.nextFloat() * 0.05F,(random.nextFloat() - random.nextFloat()) * 0.1F)).build());
              continue;
            }
          }
          EntityItem entityitem=new EntityItem(entity.worldObj,posX,posY,posZ,item);
          entityitem.setDefaultPickupDelay();
          entityitem.motionY+=random.nextFloat() * 0.05F;
          entityitem.motionX+=(random.nextFloat() - random.nextFloat()) * 0.1F;
          entityitem.motionZ+=(random.nextFloat() - random.nextFloat()) * 0.1F;
          if (currentState.getPhase().doesCaptureEntityDrops(currentState)) {
            if (currentState.tracksEntitySpecificDrops()) {
              phaseContext.getCapturedEntityItemDropSupplier().get().put(entity.getUniqueID(),entityitem);
            }
 else {
              phaseContext.getCapturedItemsSupplier().get().add(entityitem);
            }
            continue;
          }
          entity.worldObj.spawnEntityInWorld(entityitem);
        }
      }
      itemstack.damageItem(1,entity);
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
/** 
 * @author gabizou - June 21st, 2016
 * @reason Rewrites the forge handling of this to properly handlewhen sheared drops are captured by whatever current phase the {@link CauseTracker} is in.Returns true if the item can be used on the given entity, e.g. shears on sheep.
 */
@Overwrite @Override public boolean itemInteractionForEntity(ItemStack itemstack,EntityPlayer player,EntityLivingBase entity,EnumHand hand){
  if (entity.worldObj.isRemote) {
    return false;
  }
  if (entity instanceof IShearable) {
    IShearable target=(IShearable)entity;
    BlockPos pos=new BlockPos(entity.posX,entity.posY,entity.posZ);
    if (target.isShearable(itemstack,entity.worldObj,pos)) {
      List<ItemStack> drops=target.onSheared(itemstack,entity.worldObj,pos,EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE,itemstack));
      final CauseTracker causeTracker=((IMixinWorldServer)entity.worldObj).getCauseTracker();
      final PhaseData currentData=causeTracker.getCurrentPhaseData();
      final IPhaseState currentState=currentData.state;
      final PhaseContext phaseContext=currentData.context;
      final Random random=EntityUtil.fromNative(entity).getRandom();
      final IMixinEntity mixinEntity=EntityUtil.toMixin(entity);
      final double posX=entity.posX;
      final double posY=entity.posY + 1.0F;
      final double posZ=entity.posZ;
      final Vector3d position=new Vector3d(posX,posY,posZ);
      for (      ItemStack drop : drops) {
        final ItemStack item;
        if (drop.getItem() != null) {
          final ItemStackSnapshot snapshot=ItemStackUtil.createSnapshot(drop);
          final List<ItemStackSnapshot> original=new ArrayList<>();
          original.add(snapshot);
          final DropItemEvent.Pre dropEvent=SpongeEventFactory.createDropItemEventPre(Cause.of(NamedCause.source(entity)),ImmutableList.of(snapshot),original);
          if (dropEvent.isCancelled()) {
            continue;
          }
          Transform<World> suggested=new Transform<>(mixinEntity.getWorld(),position);
          SpawnCause cause=EntitySpawnCause.builder().entity(mixinEntity).type(SpawnTypes.DROPPED_ITEM).build();
          ConstructEntityEvent.Pre event=SpongeEventFactory.createConstructEntityEventPre(Cause.of(NamedCause.source(cause)),EntityTypes.ITEM,suggested);
          SpongeImpl.postEvent(event);
          item=event.isCancelled() ? null : ItemStackUtil.fromSnapshotToNative(dropEvent.getDroppedItems().get(0));
        }
 else {
          continue;
        }
        if (item == null) {
          continue;
        }
        if (item.stackSize != 0 && item.getItem() != null) {
          if (!currentState.getPhase().ignoresItemPreMerging(currentState) && SpongeImpl.getGlobalConfig().getConfig().getOptimizations().doDropsPreMergeItemDrops()) {
            if (currentState.tracksEntitySpecificDrops()) {
              final Multimap<UUID,ItemDropData> multimap=phaseContext.getCapturedEntityDropSupplier().get();
              final Collection<ItemDropData> itemStacks=multimap.get(entity.getUniqueID());
              SpongeImplHooks.addItemStackToListForSpawning(itemStacks,ItemDropData.item(item).motion(new Vector3d((random.nextFloat() - random.nextFloat()) * 0.1F,random.nextFloat() * 0.05F,(random.nextFloat() - random.nextFloat()) * 0.1F)).position(new Vector3d(posX,posY,posZ)).build());
              continue;
            }
 else {
              final List<ItemDropData> itemStacks=phaseContext.getCapturedItemStackSupplier().get();
              SpongeImplHooks.addItemStackToListForSpawning(itemStacks,ItemDropData.item(item).position(new Vector3d(posX,posY,posZ)).motion(new Vector3d((random.nextFloat() - random.nextFloat()) * 0.1F,random.nextFloat() * 0.05F,(random.nextFloat() - random.nextFloat()) * 0.1F)).build());
              continue;
            }
          }
          EntityItem entityitem=new EntityItem(entity.worldObj,posX,posY,posZ,item);
          entityitem.setDefaultPickupDelay();
          entityitem.motionY+=random.nextFloat() * 0.05F;
          entityitem.motionX+=(random.nextFloat() - random.nextFloat()) * 0.1F;
          entityitem.motionZ+=(random.nextFloat() - random.nextFloat()) * 0.1F;
          if (currentState.getPhase().doesCaptureEntityDrops(currentState)) {
            if (currentState.tracksEntitySpecificDrops()) {
              phaseContext.getCapturedEntityItemDropSupplier().get().put(entity.getUniqueID(),entityitem);
            }
 else {
              phaseContext.getCapturedItemsSupplier().get().add(entityitem);
            }
            continue;
          }
          entity.worldObj.spawnEntityInWorld(entityitem);
        }
      }
      itemstack.damageItem(1,entity);
    }
    return true;
  }
  return false;
}