Thanks for your reply.
So this is where I ended up with.
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
onclick(worldIn, playerIn, handIn);
return new ActionResult(EnumActionResult.SUCCESS, new ItemStack(this));
}
@SideOnly(Side.CLIENT)
private void onclick(World worldIn, EntityPlayer playerIn, EnumHand handIn){
RayTraceResult ray = new RayTraceResult(playerIn);
Entity entity = ray.entityHit;
if(entity == null){
} else
entity.onKillCommand();
}
}
It kills me instead of the entity.